Spaces:
Sleeping
Sleeping
File size: 997 Bytes
53dbcc1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | """Shared .env loader for local simulator and inference runs."""
from __future__ import annotations
import os
from pathlib import Path
_LOADED = False
def _candidate_env_files() -> list[Path]:
root = Path(__file__).resolve().parent
return [root / ".env.local", root / ".env"]
def load_repo_env() -> None:
global _LOADED
if _LOADED:
return
for path in _candidate_env_files():
if not path.exists():
continue
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 not key:
continue
if value and value[0] == value[-1] and value[0] in {"'", '"'}:
value = value[1:-1]
os.environ.setdefault(key, value)
_LOADED = True
|