Miroslav Simko <ms@iolabs.ch> 2026-09-02T11:50:12+02:00
Commit #48 ยท 2 snippets
.../_config.py | 27 ++++------------------ 1 file changed, 4 insertions(+), 23 deletions(-)
| 15 | """ | 15 | """ |
| 16 | 16 | ||
| 17 | from __future__ import annotations | 17 | from __future__ import annotations |
| 18 | 18 | ||
| 19 | import json | ||
| 20 | import logging | 19 | import logging |
| 21 | from collections.abc import Mapping | 20 | from collections.abc import Mapping |
| 22 | from pathlib import Path | 21 | from pathlib import Path |
| 23 | from typing import Annotated, Any, Literal, TypeAlias | 22 | from typing import Annotated, Any, Literal, TypeAlias |
| 163 | return self | 162 | return self |
| 164 | 163 | ||
| 165 | 164 | ||
| 166 | def _load_json_overrides(config_path: str | Path | None) -> dict[str, Any]: | 165 | def _load_json_overrides(config_path: str | Path | None) -> dict[str, Any]: |
| 167 | """Read a JSON override file, or return an empty mapping when there is none. | 166 | """Read a JSON override file, or return an empty mapping when there is none.""" |
| 168 | |||
| 169 | Local stand-in for the shared ``config_loader.load_json_overrides`` helper; | ||
| 170 | drop it once the shared layer exports one. | ||
| 171 | |||
| 172 | Raises: | ||
| 173 | XmlTopdownOverlayConfigError: The file is not valid JSON, or does not | ||
| 174 | hold a JSON object. | ||
| 175 | """ | ||
| 176 | if config_path is None: | 167 | if config_path is None: |
| 177 | return {} | 168 | return {} |
| 178 | path = Path(config_path) | 169 | return config_loader.load_json_overrides( |
| 179 | try: | 170 | config_path, error_cls=XmlTopdownOverlayConfigError |
| 180 | with path.open(encoding="utf-8") as handle: | 171 | ) |
| 181 | raw = json.load(handle) | ||
| 182 | except json.JSONDecodeError as exc: | ||
| 183 | raise XmlTopdownOverlayConfigError( | ||
| 184 | f"Invalid JSON in config file {path}: {exc}" | ||
| 185 | ) from exc | ||
| 186 | if not isinstance(raw, dict): | ||
| 187 | raise XmlTopdownOverlayConfigError( | ||
| 188 | f"Config file {path} must hold a JSON object, got {type(raw).__name__}" | ||
| 189 | ) | ||
| 190 | return raw | ||
| 191 | 172 | ||
| 192 | 173 | ||
| 193 | def _load_model( | 174 | def _load_model( |
| 194 | *, | 175 | *, |
_load_json_overridesstand-in dropped in favour of the shared helper now exported by common.