diff --git a/src/util/config.py b/src/util/config.py new file mode 100644 index 0000000..e0bb30a --- /dev/null +++ b/src/util/config.py @@ -0,0 +1,28 @@ +import logging +import os + +import environ + +from services.service import Singleton + +logger = logging.getLogger(__name__) + + +def init(): + env = environ.Env(DEBUG=(bool, False)) + path = os.path.join((environ.Path(__file__) - 3).__str__(), '.env') + if os.path.exists(path): + environ.Env.read_env(path) + logger.info("env file %s loaded" % path) + # no warning even if .env doesn't exist as it's not required + # e.g. for docker containers, usually environment variables are preferred. + + return env + + +class Env(metaclass=Singleton): + def __init__(self): + self.env = init() + + +env = Env().env