CyberArena / scripts /check_env.py
Hussien Haider
H
80a4a65
Raw
History Blame Contribute Delete
1.9 kB
"""Diagnostic: print the resolved .env location and all critical keys.
Run with:
python scripts/check_env.py
Useful when "missing supabase key" appears — confirms whether the
backend actually loaded CyberArena/.env or picked up a stray copy.
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
HERE = Path(__file__).resolve()
BACKEND_DIR = HERE.parent.parent
def main() -> int:
os.chdir(BACKEND_DIR)
sys.path.insert(0, str(BACKEND_DIR))
print("=" * 70)
print(f"Backend dir: {BACKEND_DIR}")
print(f"Working dir: {Path.cwd()}")
print("=" * 70)
# 1) Show every .env file we can see in the project
print("\n[1] .env files found anywhere in the project:")
for path in sorted(BACKEND_DIR.rglob(".env*")):
if "__pycache__" in path.parts:
continue
size = path.stat().st_size
print(f" - {path} ({size} bytes)")
# 2) Trigger the loader
from app._env import load_app_env
loaded = load_app_env(verbose=True)
# 3) Show what made it into os.environ
print("\n[2] os.environ values after load:")
for key in (
"SUPABASE_URL",
"SUPABASE_ANON_KEY",
"CLOUDFLARE_API_TOKEN",
"CLOUDFLARE_ACCOUNT_ID",
"CLOUDFLARE_MODEL",
"GROQ_API_KEY",
"GROQ_MODEL",
"NVIDIA_API_KEY",
"NVIDIA_MODEL",
"MISTRAL_API_KEY",
"MISTRAL_MODEL",
):
val = os.environ.get(key, "")
if not val:
print(f" {key:25s} <MISSING>")
elif "KEY" in key or "TOKEN" in key:
print(f" {key:25s} {val[:4]}{val[-4:]} (len={len(val)})")
else:
print(f" {key:25s} {val}")
print("\n[3] Loaded file:", loaded or "<NONE — using process env only>")
print("=" * 70)
return 0
if __name__ == "__main__":
raise SystemExit(main())