Skip to content

config

xdg_config_home()

Get the XDG configuration home directory.

This function checks the XDG_CONFIG_HOME environment variable and returns its value if set. If the variable is not set, it defaults to ~/.config.

Source code in src/flowcean/cli/config.py
19
20
21
22
23
24
25
def xdg_config_home() -> Path:
    """Get the XDG configuration home directory.

    This function checks the `XDG_CONFIG_HOME` environment variable and returns
    its value if set. If the variable is not set, it defaults to `~/.config`.
    """
    return _path_from_env("XDG_CONFIG_HOME", Path.home() / ".config")

load_experiment_config(**script_config)

Load and merge experiment configuration.

Merges configuration sources into a single object, with the following precedence (lowest to highest): default settings, user config from XDG directory, project config (config.yaml or specified via CLI), CLI arguments, and script-provided overrides.

Parameters:

Name Type Description Default
**script_config Any

Additional configuration overrides.

{}

Returns:

Type Description
DictConfig | ListConfig

The merged configuration object.

Source code in src/flowcean/cli/config.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def load_experiment_config(**script_config: Any) -> DictConfig | ListConfig:
    """Load and merge experiment configuration.

    Merges configuration sources into a single object, with the following
    precedence (lowest to highest): default settings, user config from XDG
    directory, project config (`config.yaml` or specified via CLI), CLI
    arguments, and script-provided overrides.

    Args:
        **script_config: Additional configuration overrides.

    Returns:
        The merged configuration object.
    """
    cli = OmegaConf.from_cli()
    if "conf" in cli:
        experiment = OmegaConf.load(cli.pop("conf"))
    else:
        experiment = _load_config(Path.cwd() / "config.yaml")

    return OmegaConf.unsafe_merge(
        OmegaConf.create(DEFAULT_CONFIG),
        _load_config(xdg_config_home() / "flowcean" / "config.yaml"),
        experiment,
        cli,
        OmegaConf.create(script_config),
    )

initialize(**kwargs)

Initialize the experiment environment.

Loads the configuration and sets up logging according to its settings.

Parameters:

Name Type Description Default
**kwargs Any

Additional configuration overrides.

{}

Returns:

Type Description
DictConfig | ListConfig

The initialized configuration object.

Source code in src/flowcean/cli/config.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def initialize(**kwargs: Any) -> DictConfig | ListConfig:
    """Initialize the experiment environment.

    Loads the configuration and sets up logging according to its settings.

    Args:
        **kwargs: Additional configuration overrides.

    Returns:
        The initialized configuration object.
    """
    conf = load_experiment_config(**kwargs)
    logging.basicConfig(**conf.logging)
    return conf