Skip to content

Reference

The main module for wehyconfig.

read_config(config_source, section='')

Read the specified configuration file.

Parameters:

Name Type Description Default
config_source str

A path to either a configuration file or a directory containing one or more configuration files.

required
section str

If the config_source is a single file, you can specify a section within the configuration file.

''

Returns: dict: A Python dictionary representation of the configuration file.

Source code in wehyconfig/wehyconfig.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def read_config(config_source: str, section="") -> dict:
    """Read the specified configuration file.

    Args:
        config_source (str): A path to either a configuration file or
            a directory containing one or more configuration files.
        section (str): If the config_source is a single file, you can
            specify a section within the configuration file.
    Returns:
        dict: A Python dictionary representation of the configuration file.
    """
    config_path = Path(config_source)
    if config_path.is_dir():
        config_files = _get_config_files(config_path)
        config = {}
        for config_file in config_files:
            config[config_file.stem] = _read_config_file(config_file)
    elif config_path.is_file():
        config = _read_config_file(config_path, section)

    return config