serialization
orchard.core.io.serialization
¶
Configuration Serialization & Persistence Utilities.
This module handles the conversion of complex Python objects (including Pydantic models and Path objects) into YAML format, ensuring thread-safe and environment-agnostic persistence to the filesystem.
AuditSaverProtocol
¶
Bases: Protocol
Protocol for run-manifest persistence (config YAML + dependency snapshot).
Enables dependency injection of auditability operations in
RootOrchestrator, keeping the constructor signature lean while
allowing full mocking in tests.
save_config(data, yaml_path)
¶
Persist configuration to a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Configuration object to serialize. |
required |
yaml_path
|
Path
|
Destination filesystem path. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Confirmed path where the YAML was written. |
Source code in orchard/core/io/serialization.py
dump_requirements(output_path)
¶
Freeze installed packages for reproducibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path
|
Filesystem path for the requirements snapshot. |
required |
dump_git_info(output_path)
¶
Persist git commit hash and working tree status for auditability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path
|
Filesystem path for the git info snapshot. |
required |
AuditSaver
¶
Default AuditSaverProtocol implementation.
Delegates to the module-level save_config_as_yaml,
dump_requirements, and dump_git_info functions —
no logic duplication.
save_config(data, yaml_path)
¶
Persist configuration to a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Configuration object to serialize. |
required |
yaml_path
|
Path
|
Destination filesystem path. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Confirmed path where the YAML was written. |
Source code in orchard/core/io/serialization.py
dump_requirements(output_path)
¶
Freeze installed packages for reproducibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path
|
Filesystem path for the requirements snapshot. |
required |
dump_git_info(output_path)
¶
Persist git commit hash and working tree status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path
|
Filesystem path for the git info snapshot. |
required |
save_config_as_yaml(data, yaml_path)
¶
Serializes and persists configuration data to a YAML file.
This function coordinates the extraction of data from potentially complex objects (supporting Pydantic models, custom portable manifests, or raw dicts), applies recursive sanitization, and performs an atomic write to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The configuration object to save. Supports objects with 'dump_portable()' or 'model_dump()' methods, or standard dictionaries. |
required |
yaml_path
|
Path
|
The destination filesystem path. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The confirmed path where the YAML was successfully written. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the data structure cannot be serialized. |
OSError
|
If a filesystem-level error occurs (permissions, disk full). |
Source code in orchard/core/io/serialization.py
dump_requirements(output_path)
¶
Freeze installed packages to a requirements file for reproducibility.
Invokes pip freeze --local to capture the exact dependency versions
of the current environment. The output is prefixed with a Python version
header for auditability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path
|
Filesystem path where the requirements file is written. |
required |
Source code in orchard/core/io/serialization.py
dump_git_info(output_path)
¶
Persist git commit hash, branch, and dirty status for run auditability.
Captures the current HEAD commit (short hash + full hash), active branch, and whether the working tree has uncommitted changes. Silently skips if git is not available or the project is not a git repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path
|
Filesystem path where the git info is written. |
required |
Source code in orchard/core/io/serialization.py
load_config_from_yaml(yaml_path)
¶
Loads a raw configuration dictionary from a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaml_path
|
Path
|
Path to the source YAML file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The loaded configuration manifest. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified path does not exist. |