"""Settings that must not live in git — database URLs. Read from the environment first, else from the git-ignored `.env` at the repo root (KEY=VALUE lines, # comments).""" import os from functools import lru_cache from pathlib import Path ENV_FILE = Path(__file__).resolve().parents[1] / ".env" @lru_cache(maxsize=1) def _values(): values = {} if ENV_FILE.exists(): for line in ENV_FILE.read_text(encoding="utf-8").splitlines(): line = line.strip() if line and not line.startswith("#") and "=" in line: key, value = line.split("=", 1) values[key.strip()] = value.strip() return values def get(key, default=None): return os.environ.get(key) or _values().get(key, default)