MCPcopy Index your code
hub / github.com/OpenBMB/ChatDev / load_dotenv_file

Function load_dotenv_file

utils/env_loader.py:11–30  ·  view source on GitHub ↗

Populate ``os.environ`` with key/value pairs from a .env file once per process.

(dotenv_path: Path | None = None)

Source from the content-addressed store, hash-verified

9
10
11def load_dotenv_file(dotenv_path: Path | None = None) -> None:
12 """Populate ``os.environ`` with key/value pairs from a .env file once per process."""
13 global _DOTENV_LOADED
14 if _DOTENV_LOADED:
15 return
16
17 path = dotenv_path or Path(".env")
18 if path.exists():
19 for line in path.read_text(encoding="utf-8").splitlines():
20 stripped = line.strip()
21 if not stripped or stripped.startswith("#"):
22 continue
23 if "=" not in stripped:
24 continue
25 key, value = stripped.split("=", 1)
26 key = key.strip()
27 value = value.strip().strip('"').strip("'")
28 os.environ.setdefault(key, value)
29
30 _DOTENV_LOADED = True
31
32
33def build_env_var_map(extra_vars: Dict[str, str] | None = None) -> Dict[str, str]:

Callers 2

app.pyFile · 0.90
prepare_design_mappingFunction · 0.90

Calls 1

splitMethod · 0.45

Tested by

no test coverage detected