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: ABC

Abstract base class for configuration loaders.

_abc_impl = <_abc._abc_data object>
abstractmethod load(filepath: Path) dict[str, Any][source]

Load configuration from file.

class loader.ConfigReader(config_file: str, configtype: ConfigType | None = None)[source]

Bases: object

Project 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: Enum

Project configuration types.

JSON = 3
TOML = 1
YAML = 2
class loader.ConfigTypeDetector[source]

Bases: object

Strategy 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: ConfigLoader

JSON configuration loader.

_abc_impl = <_abc._abc_data object>
load(filepath: Path) dict[str, Any][source]

Load configuration from file.

class loader.TomlConfigLoader[source]

Bases: ConfigLoader

TOML configuration loader.

_abc_impl = <_abc._abc_data object>
load(filepath: Path) dict[str, Any][source]

Load configuration from file.

class loader.YamlConfigLoader[source]

Bases: ConfigLoader

YAML configuration loader.

_abc_impl = <_abc._abc_data object>
load(filepath: Path) dict[str, Any][source]

Load configuration from file.