Resolve settings from env + JSON file + defaults. Memoized. Precedence: env vars win, then the JSON file, then field defaults.
()
| 27 | |
| 28 | |
| 29 | def load_settings() -> Settings: |
| 30 | """Resolve settings from env + JSON file + defaults. Memoized. |
| 31 | |
| 32 | Precedence: env vars win, then the JSON file, then field defaults. |
| 33 | """ |
| 34 | global _cached # noqa: PLW0603 |
| 35 | if _cached is None: |
| 36 | source_path = _override or _DEFAULT_PATH |
| 37 | init_kwargs: dict[str, Any] = _read_json_overrides(source_path) |
| 38 | _cached = Settings(**init_kwargs) |
| 39 | logger.debug( |
| 40 | "load_settings: resolved (override=%s, file_used=%s, json_keys=%d)", |
| 41 | _override is not None, |
| 42 | source_path.exists(), |
| 43 | sum(len(v) for v in init_kwargs.values()), |
| 44 | ) |
| 45 | return _cached |
| 46 | |
| 47 | |
| 48 | def apply_config_override(path: Path) -> None: |
no test coverage detected