fileloader#
PyAML configuration file loader.
- class ConfigLoader(path, context)[source]#
Bases:
ABCBase class for loaders that expand nested configuration references.
Store the file path and shared loading context.
- class JSONLoader(path, context)[source]#
Bases:
ConfigLoaderLoad and expand JSON configuration files.
Create a JSON loader for the given file.
- class LoadContext(include_locations=False, include_stack=<factory>)[source]#
Bases:
objectTrack state for one recursive configuration-loading session.
- loading(path)[source]#
Register a file as currently being loaded and remove it afterward.
- Raises:
PyAMLConfigCyclingException – If the file is already on the active include stack.
- class PyAMLConfigCyclingException(error_filename, path_stack)[source]#
Bases:
PyAMLExceptionRaised when a configuration file includes itself through a cycle.
Create a circular-include error.
- class RootFolder(path=None)[source]#
Bases:
objectManage the root directory used to resolve configuration paths.
Create a root folder.
If no path is provided, the current working directory is used.
- class SafeLineLoader(stream)[source]#
Bases:
SafeLoaderYAML loader that preserves line and column information for mappings.
Create the YAML loader and record the source filename.
- class YAMLLoader(path, context)[source]#
Bases:
ConfigLoaderLoad and expand YAML configuration files.
Create a YAML loader for the given file.
- load(filename, include_locations=False)[source]#
Load a configuration file.
When include_locations is False, uses the faster C-based YAML loader and skips including source location metadata.
- resolve_env(value, _context=None)[source]#
Resolve an environment variable.
- Parameters:
value (str) – Name of the environment variable.
context – Unused loading context. Present to match the resolver interface.
- Raises:
PyAMLException – If the environment variable is not set.
- resolve_file(value, context)[source]#
Load and return the contents of a configuration file.
- Parameters:
value (str) – Path to the configuration file.
context (LoadContext) – Shared loading context used to track recursive includes and detect inclusion cycles.
- Raises:
RuntimeError – If no loading context is provided.
- resolve_path(value, _context=None)[source]#
Resolve a configuration path without loading the file.
Relative paths are expanded using the configured root folder.
- Parameters:
value (str) – Path to resolve.
context – Unused loading context. Present to match the resolver interface.
- Returns:
The absolute, normalized path as a string.