Created
July 6, 2023 03:22
-
-
Save kevinknights29/e5de07a0bea33dc72bf941a7095af13b to your computer and use it in GitHub Desktop.
Config loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import sys | |
import yaml | |
from yaml.loader import SafeLoader | |
from project.utils.constants import LOGGING_FORMAT | |
from project.utils.constants import CONFIG_FILE | |
logger = logging.getLogger(__name__) | |
logger.setLevel(logging.INFO) | |
formatter = logging.Formatter(LOGGING_FORMAT) | |
console_handler = logging.StreamHandler(sys.stdout) | |
console_handler.setFormatter(formatter) | |
logger.addHandler(console_handler) | |
conf: dict = {} | |
def config() -> dict: | |
""" | |
Loads the config.yaml file and returns a dict | |
stored in config | |
Returns: | |
dict: configuration dictionary | |
""" | |
global conf | |
if not conf: | |
with open(CONFIG_FILE, encoding="utf-8") as cfg: | |
conf = yaml.load(cfg, Loader=SafeLoader) | |
logger.log(logging.INFO, "Config loaded") | |
return conf |
Author
kevinknights29
commented
Jul 6, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment