[config] adding dataclass for config
This commit is contained in:
parent
0e0aaf9f04
commit
38123cdff3
26
pyrelacs/config/config_loader.py
Normal file
26
pyrelacs/config/config_loader.py
Normal file
@ -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}")
|
Loading…
Reference in New Issue
Block a user