32 lines
733 B
Python
32 lines
733 B
Python
from typing import Any, cast
|
|
import yaml
|
|
|
|
from config import validator
|
|
from config.merger import merge_configs
|
|
|
|
|
|
def _load_config_file(file: str):
|
|
with open(file, "r") as f:
|
|
parsed = yaml.load(f, Loader=yaml.FullLoader)
|
|
return parsed
|
|
|
|
|
|
def load_config(file: str):
|
|
# Load and validate initial config
|
|
try:
|
|
loaded_conf = _load_config_file(file)
|
|
except Exception:
|
|
return {}
|
|
if not validator.validate(loaded_conf):
|
|
return {}
|
|
|
|
conf = cast(dict[str, Any], loaded_conf)
|
|
requires = cast(list[str], conf["requires"])
|
|
conf.pop("requires")
|
|
|
|
# Recursively load files
|
|
for conf_file in requires:
|
|
conf = merge_configs(conf, load_config(conf_file))
|
|
|
|
return conf
|