[config] adding config loading function

This commit is contained in:
wendtalexander 2024-10-16 08:51:59 +02:00
parent b22ef04317
commit e16211b988

View File

@ -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__":