pyaml.configuration.fileloader#
Load PyAML configuration files and expand nested references.
The loader supports YAML and JSON files, environment and path resolvers, recursive file includes, and optional source-location metadata for diagnostics.
Functions
|
Load a configuration file. |
|
Resolve an environment variable by name. |
|
Load and return the contents of a configuration file. |
|
Resolve a configuration path without loading the file. |
|
Register a function as a configuration value resolver. |
Classes
|
Base class for parsers that expand nested configuration references. |
|
Load and expand JSON configuration files. |
|
Track include state during one recursive loading session. |
|
Manage the base directory for relative configuration paths. |
|
YAML loader that preserves line and column information for mappings. |
|
Load and expand YAML configuration files. |
Exceptions
|
Raised when a configuration file includes itself through a cycle. |
- exception pyaml.configuration.fileloader.PyAMLConfigCyclingException(error_filename, path_stack)#
Bases:
PyAMLExceptionRaised when a configuration file includes itself through a cycle.
- Parameters:
error_filename (str) – File that triggered the cycle.
path_stack (list[pathlib.Path]) – Include chain leading to the cycle.
- class pyaml.configuration.fileloader.ConfigLoader(path, context)#
Bases:
ABCBase class for parsers that expand nested configuration references.
- Parameters:
path (pathlib.Path) – Configuration file being loaded.
context (LoadContext) – Shared state for recursive includes and cycle detection.
Methods
Recursively expand configuration values.
Load and parse the current configuration file.
- expand(obj)#
Recursively expand configuration values.
Dictionaries and lists are traversed recursively, while string values are resolved using the registered resolvers. All other values are returned unchanged.
- abstractmethod load()#
Load and parse the current configuration file.
- class pyaml.configuration.fileloader.JSONLoader(path, context)#
Bases:
ConfigLoaderLoad and expand JSON configuration files.
- Parameters:
path (pathlib.Path) – Configuration file being loaded.
context (LoadContext) – Shared state for recursive includes and cycle detection.
Methods
Parse the JSON file and expand nested configuration references.
- load()#
Parse the JSON file and expand nested configuration references.
- class pyaml.configuration.fileloader.LoadContext(include_locations=False, include_stack=<factory>)#
Bases:
objectTrack include state during one recursive loading session.
- Parameters:
include_locations (bool, optional) – Preserve source locations in loaded mappings.
include_stack (list[pathlib.Path], optional) – Active include chain. Usually left empty for a new session.
Methods
Temporarily add a file to the active include chain.
- loading(path)#
Temporarily add a file to the active include chain.
- Parameters:
path (pathlib.Path) – File that is about to be loaded.
- Raises:
PyAMLConfigCyclingException – If
pathis already on the active include stack.
- class pyaml.configuration.fileloader.RootFolder(path=None)#
Bases:
objectManage the base directory for relative configuration paths.
- Parameters:
path (str or pathlib.Path or None, optional) – Directory used to resolve relative paths.
Methods
Set the directory used to resolve relative configuration files.
Return the resolved configuration root directory.
Resolve a configuration path against the root directory.
- expand_path(path)#
Resolve a configuration path against the root directory.
Relative paths are interpreted relative to the configured root folder.
- Parameters:
path (str or pathlib.Path) – Path to resolve.
- Returns:
pathlib.Path – Absolute, normalized path.
- Return type:
Path
- get()#
Return the resolved configuration root directory.
- set(path)#
Set the directory used to resolve relative configuration files.
- Parameters:
path (str or pathlib.Path) – New configuration root directory.
- class pyaml.configuration.fileloader.SafeLineLoader(stream)#
Bases:
SafeLoaderYAML loader that preserves line and column information for mappings.
- Parameters:
stream (io.TextIOBase) – Stream to parse. Its
nameis recorded so errors can cite the source file.
Methods
Build a mapping and attach location metadata to it.
- construct_mapping(node, deep=False)#
Build a mapping and attach location metadata to it.
- class pyaml.configuration.fileloader.YAMLLoader(path, context)#
Bases:
ConfigLoaderLoad and expand YAML configuration files.
- Parameters:
path (pathlib.Path) – Configuration file being loaded.
context (LoadContext) – Shared state for recursive includes and cycle detection.
Methods
Parse the YAML file and expand nested configuration references.
- load()#
Parse the YAML file and expand nested configuration references.
- pyaml.configuration.fileloader.load(filename, include_locations=False)#
Load a configuration file.
When include_locations is False, uses the faster C-based YAML loader and skips including source location metadata.
- pyaml.configuration.fileloader.resolve_env(value, _context=None)#
Resolve an environment variable by name.
- Parameters:
value (str) – Name of the environment variable.
_context (LoadContext or None, optional) – Unused loading context retained for resolver compatibility.
- Returns:
str – Environment variable value.
- Raises:
PyAMLException – If the environment variable is not set.
- Return type:
str
- pyaml.configuration.fileloader.resolve_file(value, context=None)#
Load and return the contents of a configuration file.
- Parameters:
value (str) – Path to the configuration file.
context (LoadContext, optional) – Shared loading context used to detect inclusion cycles.
- Returns:
object – Parsed and expanded configuration data.
- Raises:
RuntimeError – If no loading context is provided.
- Return type:
Any
- pyaml.configuration.fileloader.resolve_path(value, _context=None)#
Resolve a configuration path without loading the file.
Relative paths are expanded using the configured root folder.
- Parameters:
value (str) – Path to resolve.
_context (LoadContext or None, optional) – Unused loading context retained for resolver compatibility.
- Returns:
str – Absolute, normalized path.
- Return type:
str
- pyaml.configuration.fileloader.resolver(name)#
Register a function as a configuration value resolver.
- Parameters:
name (str) – Prefix used to invoke the resolver (for example
"env"or"file").- Returns:
A decorator that registers the decorated function in the global resolver registry.