"""Load local development environment variables without external dependencies.""" from __future__ import annotations import os from pathlib import Path def load_local_env(path: Path, *, override: bool = False) -> None: if not path.is_file(): return for raw_line in path.read_text(encoding="utf-8").splitlines(): line = raw_line.strip() if not line or line.startswith("#") or "=" not in line: continue key, value = line.split("=", 1) key = key.strip() value = value.strip() if value[:1] == value[-1:] and value.startswith(("'", '"')): value = value[1:-1] if key and (override or not os.environ.get(key, "").strip()): # A number of launchers export optional variables as empty strings. # Treat those exactly like an unset value so a deliberate local # development configuration is not silently shadowed. os.environ[key] = value