Config#

This module contains a config library for loading yaml/json files into dicts

sed.core.config.parse_config(config=None, folder_config=None, user_config=None, system_config=None, default_config='/home/runner/work/sed/sed/sed/config/default.yaml', verbose=True)[source]#

Load the config dictionary from a file, or pass the provided config dictionary. The content of the loaded config dictionary is then completed from a set of pre-configured config files in hierarchical order, by adding missing items. These additional config files are searched for in different places on the system as detailed below. Alternatively, they can be also passed as optional arguments (file path strings or dictionaries).

Parameters:
  • config (Union[dict, str], optional) – config dictionary or file path. Files can be json or yaml. Defaults to None.

  • folder_config (Union[ dict, str, ], optional) – working-folder-based config dictionary or file path. The loaded dictionary is completed with the folder-based values, taking preference over user, system and default values. Defaults to the file “sed_config.yaml” in the current working directory.

  • user_config (Union[ dict, str, ], optional) – user-based config dictionary or file path. The loaded dictionary is completed with the user-based values, taking preference over system and default values. Defaults to the file “.sed/config.yaml” in the current user’s home directory.

  • system_config (Union[ dict, str, ], optional) – system-wide config dictionary or file path. The loaded dictionary is completed with the system-wide values, taking preference over default values. Defaults to the file “/etc/sed/config.yaml” on linux, and “%ALLUSERSPROFILE%/sed/config.yaml” on windows.

  • default_config (Union[ dict, str, ], optional) – default config dictionary or file path. The loaded dictionary is completed with the default values. Defaults to package_dir/config/default.yaml”.

  • verbose (bool, optional) – Option to report loaded config files. Defaults to True.

Raises:
  • TypeError – Raised if the provided file is neither json nor yaml.

  • FileNotFoundError – Raised if the provided file is not found.

Returns:

Loaded and possibly completed config dictionary.

Return type:

dict

sed.core.config.load_config(config_path)[source]#

Loads config parameter files.

Parameters:

config_path (str) – Path to the config file. Json or Yaml format are supported.

Raises:
  • FileNotFoundError – Raised if the config file cannot be found.

  • TypeError – Raised if the provided file is neither json nor yaml.

Returns:

loaded config dictionary

Return type:

dict

sed.core.config.save_config(config_dict, config_path, overwrite=False)[source]#

Function to save a given config dictionary to a json or yaml file. Normally, it loads any existing file of the given name, and keeps any existing dictionary keys not present in the provided dictionary. The overwrite option creates a fully empty dictionary first.

Parameters:
  • config_dict (dict) – The dictionary to save.

  • config_path (str) – A string containing the path to the file where to save the dictionary to.

  • overwrite (bool, optional) – Option to overwrite an existing file with the given dictionary. Defaults to False.

sed.core.config.complete_dictionary(dictionary, base_dictionary)[source]#

Iteratively completes a dictionary from a base dictionary, by adding keys that are missing in the dictionary, and are present in the base dictionary.

Parameters:
  • dictionary (dict) – the dictionary to be completed.

  • base_dictionary (dict) – the base dictionary.

Returns:

the completed (merged) dictionary

Return type:

dict