33 lines
832 B
Python
33 lines
832 B
Python
from typing import Any, cast
|
|
import yaml
|
|
|
|
from config import validator
|
|
from config.dtype import ArchMgrConfig
|
|
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) -> ArchMgrConfig:
|
|
# Load and validate initial config
|
|
try:
|
|
loaded_conf = _load_config_file(file)
|
|
except Exception:
|
|
return {}
|
|
if not validator.validate(loaded_conf):
|
|
return {}
|
|
|
|
configuration = cast(dict[str, Any], loaded_conf)
|
|
requires = cast(list[str], configuration.pop("requires"))
|
|
conf = cast(ArchMgrConfig, configuration)
|
|
|
|
# Recursively load files
|
|
for conf_file in requires:
|
|
conf = merge_configs(conf, load_config(conf_file))
|
|
|
|
return conf
|