From d24d91bbc5cf1b02c68ed11386de0680fdd35501 Mon Sep 17 00:00:00 2001 From: charlene tau express Date: Fri, 14 Mar 2025 18:00:36 +0800 Subject: [PATCH] added config.py for env variables but not working yet --- src/util/config.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/util/config.py 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