loader
YAML configuration loading with source location tracking.
Loader
Load YAML configuration files with source location tracking.
Handles loading YAML files and tracking where each config item came from, without polluting the config dictionaries with metadata keys.
Example
Source code in src/sparkwheel/loader.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
_load_yaml_with_metadata(stream, filepath, registry)
Load YAML and populate metadata registry during construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
File stream to load from |
required | |
filepath
|
str
|
Path string for error messages |
required |
registry
|
MetadataRegistry
|
MetadataRegistry to populate |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Config dictionary (clean, no metadata keys) |
Source code in src/sparkwheel/loader.py
_strip_metadata(config)
staticmethod
Remove sparkwheel_metadata keys from config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any
|
Config structure potentially containing metadata keys |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Config with metadata keys removed |
Source code in src/sparkwheel/loader.py
load_file(filepath)
Load a single YAML file with metadata tracking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
PathLike
|
Path to YAML file |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], MetadataRegistry]
|
Tuple of (config_dict, metadata_registry) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If file is not a YAML file |
Source code in src/sparkwheel/loader.py
load_files(filepaths)
Load multiple YAML files sequentially.
Files are loaded in order and merged using simple dict update (not the merge_configs logic - that happens at a higher level).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepaths
|
Sequence[PathLike]
|
Sequence of file paths to load |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], MetadataRegistry]
|
Tuple of (merged_config_dict, merged_metadata_registry) |
Source code in src/sparkwheel/loader.py
MetadataTrackingYamlLoader
Bases: CheckKeyDuplicatesYamlLoader
YAML loader that tracks source locations into MetadataRegistry.
Unlike the old approach that added sparkwheel_metadata keys to dicts, this loader populates a separate MetadataRegistry during loading.
Source code in src/sparkwheel/loader.py
construct_mapping(node, deep=False)
Override to track source locations for dict nodes.
Source code in src/sparkwheel/loader.py
construct_sequence(node, deep=False)
Override to track source locations for list nodes.