nicetoolbox.configs.utils

Functions

default_auto_placeholders

default_runtime_placeholders

dict_to_model

Converts and validate dict to pydantic model

get_latest_experiment_config_path

keys_collision_dict

Returns key collision between two dictionaries

load_raw_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.

merge_dicts

Merge two dictionaries, raising an error if any keys overlap.

model_to_dict

Converts pydantic model into the primitives dict

Exceptions

ConfigValidationError(error[, filepath])

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.

nicetoolbox.configs.utils.merge_dicts(a: dict, b: dict) dict[source]

Merge two dictionaries, raising an error if any keys overlap.

nicetoolbox.configs.utils.model_to_dict(model: BaseModel) dict[source]

Converts pydantic model into the primitives dict