Skip to content
Snippets Groups Projects
Commit ae5286cb authored by Simon Künzel's avatar Simon Künzel
Browse files

Move config loading to common

parent 801a38ff
Branches
No related tags found
No related merge requests found
import os
from pathlib import Path
from videoag_common.miscellaneous.util import load_config_file, merge_config_with
if "VIDEOAG_CONFIG" not in os.environ:
raise Exception("Missing VIDEOAG_CONFIG environment variable")
config = load_config_file(Path(os.getcwd()).joinpath(os.environ["VIDEOAG_CONFIG"]))
if "VIDEOAG_TEST_CONFIG_OVERRIDE" in os.environ:
merge_config_with(
config,
load_config_file(Path(os.getcwd()).joinpath(os.environ["VIDEOAG_TEST_CONFIG_OVERRIDE"]))
)
......@@ -112,3 +112,16 @@ def load_config_file(path: Path):
if key.isupper():
config[key] = getattr(config_module, key)
return config
def merge_config_with(config: dict, to_merge: dict, overwrite_non_mergeable: bool = False):
for key, item in to_merge:
if key not in config:
config[key] = item
elif isinstance(item, dict) and isinstance(config[key], dict):
merge_config_with(config[key], item)
elif overwrite_non_mergeable:
config[key] = item
else:
# Don't leak config values, might contain passwords, etc.
raise ValueError(f"Can't merge {type(item)} into {type(config[key])} for key {key}")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment