ankimaker/src/ankimaker/config/load_config.py
2022-12-08 18:43:24 +11:00

21 lines
647 B
Python

import os
import yaml
from pathlib import Path
from .configuration import AnkimakerConfig
def load_config_file(file_path: str):
"""
Load yaml configuration file.
:param file_path: Path to yaml file with configuration
:return: Dict config
"""
file_path = Path(file_path if '~' not in file_path else os.path.expanduser(file_path))
assert file_path.exists()
assert file_path.is_file()
with open(file_path, 'r') as file:
yaml.add_path_resolver('!ankimakerconfig', ['AnkimakerConfig'], dict)
configuration = yaml.load(file.read(), Loader=yaml.Loader)
AnkimakerConfig.loader(configuration)