loader module¶
Loader module for NGPASM.
This module provides functionality for reading configuration files with support for multiple formats and proper error handling.
- class loader.ConfigLoader[source]¶
Bases:
ABCAbstract base class for configuration loaders.
- _abc_impl = <_abc._abc_data object>¶
- class loader.ConfigReader(config_file: str, configtype: ConfigType | None = None)[source]¶
Bases:
objectProject configuration reader with strategy pattern.
This class uses different loaders based on configuration type and provides consistent error handling.
- __init__(config_file: str, configtype: ConfigType | None = None) None[source]¶
Initialize configuration reader.
- Parameters:
config_file – Path to configuration file
configtype – Explicit config type (auto-detected if None)
- Raises:
FileNotFoundError – If config file doesn’t exist
TypeError – If loaded data is not a dictionary
- _load_data() dict[str, Any][source]¶
Load configuration data using appropriate loader.
- Returns:
Loaded data as dictionary
- Raises:
FileNotFoundError – If config file doesn’t exist
TypeError – If loaded data is not a dictionary
- _loaders: dict[ConfigType, JsonConfigLoader | TomlConfigLoader | YamlConfigLoader] = {ConfigType.JSON: <loader.JsonConfigLoader object>, ConfigType.TOML: <loader.TomlConfigLoader object>, ConfigType.YAML: <loader.YamlConfigLoader object>}¶
- class loader.ConfigType(*values)[source]¶
Bases:
EnumProject configuration types.
- JSON = 3¶
- TOML = 1¶
- YAML = 2¶
- class loader.ConfigTypeDetector[source]¶
Bases:
objectStrategy for detecting configuration file types.
- __init__() None¶
- static by_extension(extension: str) ConfigType[source]¶
Detect config type by file extension.
- Parameters:
extension – File extension string
- Returns:
Detected config type (defaults to JSON)
- static by_filename(filename: str) ConfigType[source]¶
Detect config type by filename.
- Parameters:
filename – Full filename or path
- Returns:
Detected config type
- class loader.JsonConfigLoader[source]¶
Bases:
ConfigLoaderJSON configuration loader.
- _abc_impl = <_abc._abc_data object>¶
- class loader.TomlConfigLoader[source]¶
Bases:
ConfigLoaderTOML configuration loader.
- _abc_impl = <_abc._abc_data object>¶