24 lines
682 B
Python
Executable File
24 lines
682 B
Python
Executable File
"""Load local development environment variables without external dependencies."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
|
|
def load_local_env(path: Path) -> 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:
|
|
os.environ.setdefault(key, value)
|
|
|