peal.global_utils.load_yaml_config

peal.global_utils.load_yaml_config(config_path, config_model=None, return_namespace=True)[source]

Load a config file (or dict) into its pydantic model.

The central entry point used all over PEAL. The yaml is read with all path placeholders expanded and nested yamls inlined. If no config_model is given but the data identifies itself through config_name or category/<category>_type, the model is looked up with get_config_model(); a failure there is only warned about. With a model, nested dicts and lists of dicts are converted first, the model is instantiated and propagate_seed() is run. Without one, the dict is either wrapped in a SimpleNamespace or returned as is.

Parameters:
  • config_path (str or dict or object) – Path of a .yaml file, an already loaded dict, or a config object, which is passed through unchanged.

  • config_model (type, optional) – The pydantic class to instantiate; inferred when omitted.

  • return_namespace (bool, optional) – Wrap a model-less dict in a types.SimpleNamespace instead of returning the plain dict. Set to False for nested dicts, which pydantic wants to receive as dicts.

Returns:

The config: an instance of config_model, a SimpleNamespace or the raw data.

Return type:

object

Raises:

Exception – If config_path is a string that does not end in .yaml.