added config.py for env variables but not working yet
This commit is contained in:
parent
17b66f2051
commit
d24d91bbc5
28
src/util/config.py
Normal file
28
src/util/config.py
Normal file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user