From 38123cdff3131d9cbe82b58396af7c0f484b2e6e Mon Sep 17 00:00:00 2001 From: wendtalexander Date: Mon, 14 Oct 2024 08:40:52 +0200 Subject: [PATCH] [config] adding dataclass for config --- pyrelacs/config/config_loader.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 pyrelacs/config/config_loader.py diff --git a/pyrelacs/config/config_loader.py b/pyrelacs/config/config_loader.py new file mode 100644 index 0000000..c6c5f4c --- /dev/null +++ b/pyrelacs/config/config_loader.py @@ -0,0 +1,26 @@ +from dataclasses import dataclass +import pathlib + +import yaml +from IPython import embed + +from pyrelacs.util.logging import config_logging + +log = config_logging() + + +@dataclass +class Config: + # Path: str + + @classmethod + def load_config(cls): + pyrelacs_config_path = pathlib.Path(__file__).parent / "config.yaml" + log.debug(pyrelacs_config_path) + if not pyrelacs_config_path.is_file(): + log.error("Config File was not found") + with open(pyrelacs_config_path, "r") as config_file: + try: + return yaml.full_load(config_file) + except yaml.YAMLError as e: + raise yaml.YAMLError(f"Error parsing YAML file: {e}")