adc_toolkit.utils.load_config

This module contains functions for loading of settings and configurations.

 1"""This module contains functions for loading of settings and configurations."""
 2
 3import os
 4from pathlib import Path
 5from typing import Any
 6
 7import yaml
 8
 9
10def get_config_directory() -> str:
11    """
12    Find the path of the adc_toolkit config directory.
13
14    If not specified in ACMETRIC_CONFIG_DIR environment variable, the default path is used.
15
16    Returns:
17        str: Value of the environment variable that specifies the adc_toolkit config directory.
18    """
19    return str(Path(__file__).parents[1] / "configuration/base")
20
21
22def load_settings(file_path: str) -> dict[str, Any]:
23    """
24    Load settings from a YAML configuration file.
25
26    Args:
27        file_path (str): Path to the configuration file.
28
29    Returns:
30        dict: Loaded settings from the YAML file.
31    """
32    settings: dict[str, Any] = {}
33
34    if os.path.exists(file_path):
35        try:
36            with open(file_path) as file:
37                settings = yaml.safe_load(file) or {}
38        except (FileNotFoundError, yaml.YAMLError):
39            raise
40    else:
41        raise FileNotFoundError(f"Config file {file_path} not found.")
42
43    return settings
def get_config_directory() -> str:
11def get_config_directory() -> str:
12    """
13    Find the path of the adc_toolkit config directory.
14
15    If not specified in ACMETRIC_CONFIG_DIR environment variable, the default path is used.
16
17    Returns:
18        str: Value of the environment variable that specifies the adc_toolkit config directory.
19    """
20    return str(Path(__file__).parents[1] / "configuration/base")

Find the path of the adc_toolkit config directory.

If not specified in ACMETRIC_CONFIG_DIR environment variable, the default path is used.

Returns: str: Value of the environment variable that specifies the adc_toolkit config directory.

def load_settings(file_path: str) -> dict[str, typing.Any]:
23def load_settings(file_path: str) -> dict[str, Any]:
24    """
25    Load settings from a YAML configuration file.
26
27    Args:
28        file_path (str): Path to the configuration file.
29
30    Returns:
31        dict: Loaded settings from the YAML file.
32    """
33    settings: dict[str, Any] = {}
34
35    if os.path.exists(file_path):
36        try:
37            with open(file_path) as file:
38                settings = yaml.safe_load(file) or {}
39        except (FileNotFoundError, yaml.YAMLError):
40            raise
41    else:
42        raise FileNotFoundError(f"Config file {file_path} not found.")
43
44    return settings

Load settings from a YAML configuration file.

Args: file_path (str): Path to the configuration file.

Returns: dict: Loaded settings from the YAML file.