Simplify package structure

This commit is contained in:
Kristóf Tóth
2019-07-24 15:50:41 +02:00
parent a23224aced
commit 52399f413c
79 changed files with 22 additions and 24 deletions

1
tfw/config/__init__.py Normal file
View File

@ -0,0 +1 @@
from .envvars import TFWENV, TAOENV

5
tfw/config/envvars.py Normal file
View File

@ -0,0 +1,5 @@
from .lazy_environment import LazyEnvironment
TFWENV = LazyEnvironment('TFW_', 'tfwenvtuple').environment
TAOENV = LazyEnvironment('AVATAO_', 'taoenvtuple').environment

View File

@ -0,0 +1,22 @@
from collections import namedtuple
from os import environ
from tfw.internals.lazy import lazy_property
class LazyEnvironment:
def __init__(self, prefix, tuple_name):
self._prefix = prefix
self._tuple_name = tuple_name
@lazy_property
def environment(self):
return self.prefixed_envvars_to_namedtuple()
def prefixed_envvars_to_namedtuple(self):
envvars = {
envvar.replace(self._prefix, '', 1): environ.get(envvar)
for envvar in environ.keys()
if envvar.startswith(self._prefix)
}
return namedtuple(self._tuple_name, envvars)(**envvars)