# auto-generated ai_brain_env.py # import this near top of python entrypoints to load same env files as the shell loader import os from pathlib import Path import re CANDIDATES = [ Path.home() / "Desktop" / "env", Path.home() / "Desktop" / "AI_Brain" / "env", Path.home() / "The AI" / "env", Path.home() / "env", ] ENV_DIR = None for p in CANDIDATES: if p.is_dir(): ENV_DIR = p break if ENV_DIR is None: # nothing to load # print("ai_brain_env: no env folder found") pass else: for f in sorted(ENV_DIR.glob("*.env")): if f.name.endswith(".example.env"): continue try: text = f.read_text(encoding="utf-8") except Exception: continue for line in text.splitlines(): line = line.strip() if not line or line.startswith("#"): continue m = re.match(r'^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$', line) if not m: continue k, v = m.group(1), m.group(2) # remove surrounding quotes if present if (v.startswith('"') and v.endswith('"')) or (v.startswith("'") and v.endswith("'")): v = v[1:-1] # only set if not already present (don't override) os.environ.setdefault(k, v)