| 1234567891011121314151617 |
- """从 backend/.env 加载环境变量(供联调脚本使用)"""
- from pathlib import Path
- def load_backend_env() -> dict[str, str]:
- env_path = Path(__file__).resolve().parent.parent / '.env'
- result: dict[str, str] = {}
- if not env_path.exists():
- return result
- for line in env_path.read_text(encoding='utf-8').splitlines():
- line = line.strip()
- if not line or line.startswith('#') or '=' not in line:
- continue
- key, _, value = line.partition('=')
- result[key.strip()] = value.strip()
- return result
|