From e16211b9884f19b1ed2578f4f3b5dcbc951fa335 Mon Sep 17 00:00:00 2001
From: wendtalexander <wendtalexander@protonmail.com>
Date: Wed, 16 Oct 2024 08:51:59 +0200
Subject: [PATCH] [config] adding config loading function

---
 pyrelacs/config/config_loader.py | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/pyrelacs/config/config_loader.py b/pyrelacs/config/config_loader.py
index b1a226d..ae76d90 100644
--- a/pyrelacs/config/config_loader.py
+++ b/pyrelacs/config/config_loader.py
@@ -102,17 +102,22 @@ class Config:
     metadata: Metadata
     pyrelacs: PyRelacs
 
-    @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:
+
+def load_config():
+    pyrelacs_config_path = pathlib.Path(__file__).parent.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:
+            data = yaml.full_load(config_file)
             try:
-                return yaml.full_load(config_file)
-            except yaml.YAMLError as e:
-                raise yaml.YAMLError(f"Error parsing YAML file: {e}")
+                config = from_dict(data_class=Config, data=data)
+                return config
+            except dacite.DaciteError as e:
+                log.error(f"Invalid Config, {e}")
+        except yaml.YAMLError as e:
+            raise yaml.YAMLError(f"Error parsing YAML file: {e}")
 
 
 if __name__ == "__main__":