nicetoolbox.configs.config_handler

Functions

load_config

Load a configuration file in TOML format.

load_validated_config_raw

Load a configuration file, validate it using a Pydantic model and return the raw dictionary.

Exceptions

ConfigValidationError(error[, filepath])

Custom exception for configuration validation errors.

exception nicetoolbox.configs.config_handler.ConfigValidationError(error: ValidationError, filepath: Path | None = None)[source]

Custom exception for configuration validation errors. Provides better formatting for Pydantic validation errors.

nicetoolbox.configs.config_handler.load_config(config_file: str) dict[source]

Load a configuration file in TOML format.

Parameters:

config_file (str) – The path to the configuration file.

Returns:

The configuration data loaded from the file.

Return type:

dict

Raises:
  • IOError – When an array with no valid (existing).

  • FileNotFoundError – If the file does not exist.

  • NotImplementedError – If the file type is not supported.

  • TomlDecodeError – Error while decoding toml.

Note

If the operating system is Windows, the paths in the configuration data will be converted to Windows format.

nicetoolbox.configs.config_handler.load_validated_config_raw(config_filepath: str, schema: Type[ModelT]) dict[source]

Load a configuration file, validate it using a Pydantic model and return the raw dictionary.

Parameters:
  • config_filepath (str) – Path to the config file.

  • schema (Type[ModelT]) – Pydantic model class used to validate.

Returns:

Raw config dictionary.

Return type:

dict

Raises:
  • IOError – When an array with no valid (existing)

  • FileNotFoundError – If the file does not exist.

  • NotImplementedError – If the file type is not supported.

  • TomlDecodeError – Error while decoding toml

  • ConfigValidationError – If validation fails.