cliconfig.process_routines
Routines to manipulate dictionaries with processing.
Used by config_routines
.
- merge_flat_processing(config1, config2, *, allow_new_keys=True, preprocess_first=True, preprocess_second=True, postprocess=True)
Flatten, merge config2 into config1 and apply pre and post processing.
Work even if the config dicts have a mix of nested and flat dictionaries. If both arguments are configs, the process lists are merged before applying the processing. The duplicate processings (with same internal variables) are removed.
- Parameters:
config1 (Config) – The first config.
config2 (Config) – The second dict to merge into config1.
allow_new_keys (bool, optional) – If True, new keys (that are not in config1) are allowed in config2. Otherwise, it raises an error. By default True.
preprocess_first (bool, optional) – If True, apply pre-merge processing to config1. By default True.
preprocess_second (bool, optional) – If True, apply pre-merge processing to config2. By default True.
postprocess (bool, optional) – If True, apply post-merge processing to the merged config. By default True.
- Raises:
ValueError – If allow_new_keys is False and config2 has new keys that are not in config1.
ValueError – If there are conflicting keys when flatten one of the dicts.
- Returns:
flat_config – The merged flat config.
- Return type:
- merge_flat_paths_processing(config_or_path1, config_or_path2, *, additional_process=None, allow_new_keys=True, preprocess_first=True, preprocess_second=True, postprocess=True)
Flatten, merge and apply processing to two configs or their yaml paths.
Similar to
merge_flat_processing()
but allows to pass configs or their yaml paths. Work even if the configs have a mix of nested and flat dicts. If both arguments are configs, the process lists are merged before applying the processing. The duplicate processings (with same internal variables) are removed.- Parameters:
config_or_path1 (Union[str, Config]) – The first config or its path.
config_or_path2 (Union[str, Config]) – The second config or its path, to merge into first config.
additional_process (Optional[List[Processing]], optional) – Additional processings to apply to the merged config. It can be useful to merge a config from its path while it has some specific processings.
allow_new_keys (bool, optional) – If True, new keys (that are not in config1) are allowed in config2. Otherwise, it raises an error. By default True.
preprocess_first (bool, optional) – If True, apply pre-merge processing to config1. By default True.
preprocess_second (bool, optional) – If True, apply pre-merge processing to config2. By default True.
postprocess (bool, optional) – If True, apply post-merge processing to the merged config. By default True.
- Raises:
ValueError – If allow_new_keys is False and config2 has new keys that are not in config1.
ValueError – If there are conflicting keys when flatten one of the dicts.
- Returns:
flat_config – The merged flat config.
- Return type:
- save_processing(config, path)
Save a config and apply pre-save processing before saving.
- load_processing(path, process_list)
Load a dict from yaml file path and apply post-load processing.
- Parameters:
path (str) – The path to the file to load the dict.
process_list (List[Processing]) – The list of processing to apply after loading. Only post-load processing is applied. The order of the processing is given by the postload_order attribute of the processing.
- Returns:
flat_config – The loaded flat config.
- Return type: