io¶
src.utils.io
¶
Safe JSON and YAML file I/O helpers.
All generators and enrichers should use these helpers instead of raw
json.load / yaml.safe_load to get consistent error messages and
graceful handling of missing or malformed files.
load_json(path: str | Path, *, default: Any = None) -> Any
¶
Read and parse a JSON file.
Returns default (None) when the file is missing or unparseable,
logging a warning in either case.
Source code in src/utils/io.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
save_json(path: str | Path, data: Any, *, indent: int = 2) -> None
¶
Write data as pretty-printed JSON, creating parent dirs as needed.
Source code in src/utils/io.py
38 39 40 41 42 43 44 | |
load_yaml(path: str | Path, *, default: Any = None) -> Any
¶
Read and parse a YAML file.
Returns default (None) when the file is missing or unparseable,
logging a warning in either case.
Source code in src/utils/io.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
save_yaml(path: str | Path, data: Any) -> None
¶
Write data as YAML, creating parent dirs as needed.
Source code in src/utils/io.py
65 66 67 68 69 70 | |