Spaces:
Sleeping
Sleeping
File size: 737 Bytes
86c3e08 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | from __future__ import annotations
import os
from pathlib import Path
def load_env_file(path: str | Path | None = None) -> None:
"""Load key-value pairs from .env without overriding existing env vars."""
env_path = Path(path) if path is not None else Path(__file__).resolve().parents[1] / ".env"
if not env_path.exists():
return
for raw_line in env_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().strip('"').strip("'")
if key and key not in os.environ:
os.environ[key] = value
|