commit 99f770b20b1213d66521a706ebebcc4f146e279a
parent babb84b386e72bb8796ba3adb92d85ac7b6c791e
Author: lash <dev@holbrook.no>
Date: Sun, 6 Mar 2022 19:06:36 +0000
Apply empty directives from override config dirs
Diffstat:
6 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,5 @@
+0.6.0
+ - Empty entries in override config dirs now empties value in directive (was previously skipped)
0.5.7
- Overwrite config with empty but defined environment variables
0.5.6
diff --git a/confini/config.py b/confini/config.py
@@ -201,7 +201,7 @@ class Config:
self.__process_doc_(d)
- def __process_schema_dir(self, in_dir):
+ def __process_schema_dir(self, in_dir, allow_empty=False):
d = os.listdir(in_dir)
d.sort()
c = 0
@@ -232,7 +232,7 @@ class Config:
raise KeyError('config overrides in {} defines key {} not present in default config {}'.format(self.dirs[i], k, self.dirs[0]))
v = local_parser.get(s, so)
logg.debug('checking {} {} {}'.format(k, s, so))
- if not self.is_as_none(v):
+ if allow_empty or not self.is_as_none(v):
logg.debug('multi config file overrides {}'.format(k))
self.add(v, k, exists_ok=True)
self.set_dir(k, self.dirs[i])
@@ -247,7 +247,7 @@ class Config:
self.__collect_dir(tmp_dir)
- self.__process_schema_dir(tmp_dir)
+ self.__process_schema_dir(tmp_dir, allow_empty=True)
self.__sections_override(os.environ, 'environment variable', allow_empty=True)
diff --git a/setup.py b/setup.py
@@ -6,7 +6,7 @@ f.close()
setup(
name='confini',
- version='0.5.7',
+ version='0.6.0',
description='Parse, verify and merge all ini files in a single directory',
author='Louis Holbrook',
author_email='dev@holbrook.no',
diff --git a/tests/files/multi/one/foo.ini b/tests/files/multi/one/foo.ini
@@ -1,4 +1,4 @@
[FOO]
bar = xyzzy
baz =
-bah =
+bah = 123
diff --git a/tests/test_env.py b/tests/test_env.py
@@ -78,13 +78,24 @@ class TestEnv(unittest.TestCase):
c = Config(inidir, env_prefix='ZZZ')
c.process()
expect = {
- 'FOO_BAR': '42',
+ 'FOO_BAR': '',
'FOO_BAZ': '029a',
'BAR_FOO': 'oof',
'XYZZY_BERT': 'ernie',
}
self.assertDictEqual(expect, c.store)
+ del os.environ['ZZZ_FOO_BAR']
+ inidir = os.path.join(self.wd, 'files')
+ c = Config(inidir, env_prefix='ZZZ')
+ c.process()
+ expect = {
+ 'FOO_BAR': '42',
+ 'FOO_BAZ': '029a',
+ 'BAR_FOO': 'oof',
+ 'XYZZY_BERT': 'ernie',
+ }
+ self.assertDictEqual(expect, c.store)
def test_env_parser(self):
envpath = os.path.join(self.wd, 'files', 'env', 'env.txt')
diff --git a/tests/test_multi.py b/tests/test_multi.py
@@ -37,6 +37,17 @@ class TestBasic(unittest.TestCase):
self.assertEqual(r, 'three')
+ def test_parse_two_one_undef(self):
+ inidir_one = os.path.join(self.wd, 'files', 'multi', 'one')
+ inidir_two = os.path.join(self.wd, 'files', 'multi', 'four')
+ c = Config(inidir_one, override_dirs=[inidir_two])
+ c.process()
+ r = c.get('FOO_BAH')
+ self.assertEqual(r, '123')
+ r = c.get('FOO_BAZ')
+ self.assertEqual(r, '42')
+
+
def test_parse_two_schema_error(self):
inidir_one = os.path.join(self.wd, 'files', 'multi', 'one')
inidir_two = os.path.join(self.wd, 'files', 'multi', 'three')