dissertation/where_fi/config/__init__.py
Christos Falas 381dcaa0bc
[BROKEN] Add CLI option for option
This is still slightly broken, as new processes are not able to access
the configuration.
2025-01-27 16:16:40 +00:00

31 lines
658 B
Python

import logging
import sys
from pathlib import Path
import pydantic
import yaml
from . import models
logger = logging.getLogger(__name__)
config: models.Config | None = None
def load(path: Path) -> None:
global config
try:
config_yaml = yaml.safe_load(open(path))
except FileNotFoundError:
logger.error(
"No config.yaml file found. Make sure to copy the "
"config.example.yaml file to config.yaml"
)
sys.exit(1)
try:
config = models.Config(**config_yaml)
except pydantic.ValidationError as e:
logger.error(f"Invalid config.yaml file: {e}")
sys.exit(1)