commit babb84b386e72bb8796ba3adb92d85ac7b6c791e
parent 24c03b353029e2695c42c5ee371be2c57547b3e7
Author: lash <dev@holbrook.no>
Date: Thu, 24 Feb 2022 15:50:34 +0000
Enable overwrite of empty but defined environment variable values
Diffstat:
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,5 @@
+0.5.7
+ - Overwrite config with empty but defined environment variables
0.5.6
- Add manpage
0.5.5
diff --git a/confini/config.py b/confini/config.py
@@ -126,27 +126,29 @@ class Config:
return True
- def __sections_override(self, dct, dct_description):
+ def __sections_override(self, dct, dct_description, allow_empty=False):
for s in self.parser.sections():
for k in self.parser[s]:
cn = to_constant_name(k, s)
- self.override(cn, self.parser[s][k], dct, dct_description)
+ self.override(cn, self.parser[s][k], dct, dct_description, allow_empty=True)
- def dict_override(self, dct, dct_description):
+ def dict_override(self, dct, dct_description, allow_empty=False):
for k in dct.keys():
try:
- self.override(k, self.store[k], dct, dct_description)
+ self.override(k, self.store[k], dct, dct_description, allow_empty=allow_empty)
except KeyError:
logg.warning('override key {} have no match in config store'.format(k))
- def override(self, cn, v, dct, dct_description):
+ def override(self, cn, v, dct, dct_description, allow_empty=False):
cn_env = cn
if self.env_prefix != None:
cn_env = self.env_prefix + cn
val = dct.get(cn_env)
- if val == None or val == '':
+ if val == None:
+ val = self.store.get(cn, v)
+ elif val == '' and not allow_empty:
val = self.store.get(cn, v)
else:
logg.info('{} {} overrides {}'.format(dct_description, cn_env, cn))
@@ -247,7 +249,7 @@ class Config:
self.__process_schema_dir(tmp_dir)
- self.__sections_override(os.environ, 'environment variable')
+ self.__sections_override(os.environ, 'environment variable', allow_empty=True)
if set_as_current:
set_current(self, description=self.dir)
diff --git a/setup.py b/setup.py
@@ -6,7 +6,7 @@ f.close()
setup(
name='confini',
- version='0.5.6',
+ version='0.5.7',
description='Parse, verify and merge all ini files in a single directory',
author='Louis Holbrook',
author_email='dev@holbrook.no',