nicetoolbox.configs.utils¶
Functions
Converts and validate dict to pydantic model |
|
Returns key collision between two dictionaries |
|
Load a configuration file in TOML format. |
|
Load a configuration file, validate it using a Pydantic model and return the raw dictionary. |
|
Merge two dictionaries, raising an error if any keys overlap. |
|
Converts pydantic model into the primitives dict |
Exceptions
|
Custom exception for configuration validation errors. |
- exception nicetoolbox.configs.utils.ConfigValidationError(error: ValidationError, filepath: Path | None = None)[source]¶
Custom exception for configuration validation errors. Provides better formatting for Pydantic validation errors.
- nicetoolbox.configs.utils.dict_to_model(config_raw: dict, schema: type[ModelT]) ModelT[source]¶
Converts and validate dict to pydantic model
- nicetoolbox.configs.utils.keys_collision_dict(a: dict, b: dict) set[source]¶
Returns key collision between two dictionaries
- nicetoolbox.configs.utils.load_raw_config(config_file: Path) dict[source]¶
Load a configuration file in TOML format.
- Parameters:
config_file (Path) – 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.utils.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.