Skip to content

Config

Module to load configuration data.

Functions

load_config: Loads the configuration file

dump_config(settings)

Dumps config settings to config file.

Puts the contents of the settings dict into the settings config file.

Parameters:

Name Type Description Default
settings dict

a dict containing config data in key, value pairs.

required
Source code in report_generator/config.py
28
29
30
31
32
33
34
35
36
37
38
39
40
def dump_config(settings: dict) -> None:
    """Dumps config settings to config file.

    Puts the contents of the settings dict into the settings
    config file.

    Args:
        settings (dict):    a dict containing config data in key,
                            value pairs.

    """
    with open("config.yaml", "w", encoding="utf-8") as file:
        yaml.dump(settings, file)

load_config()

Load data from config file.

Loads data from the config.yaml file. If the file is not found a None value is returned.

Returns:

Name Type Description
config dict

dict with config data in key, value pairs.

Source code in report_generator/config.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def load_config() -> dict:
    """Load data from config file.

    Loads data from the config.yaml file. If the
    file is not found a None value is returned.

    Returns:
        config (dict):      dict with config data in key,
                            value pairs.
    """
    config = None
    try:
        with open("config.yaml", "r", encoding="utf-8") as file:
            config = yaml.load(file, Loader=yaml.loader.SafeLoader)
        return config
    except FileNotFoundError:
        return config