confini

Parse and merge multiple ini files in python3
git clone git://git.defalsify.org/python-confini.git
Log | Files | Refs | README | LICENSE

commit 0d49e7d6e0c3c27e33137d8fdaf690df24d89649
parent aacf8f1825fb8b7f74c2551001577e1aa5f573cf
Author: nolash <dev@holbrook.no>
Date:   Tue,  2 Nov 2021 09:29:58 +0100

Add section doc string

Diffstat:
Mconfini/env.py | 6+++++-
Mconfini/export.py | 8++++++++
Mtests/files/.confini | 1+
Mtests/files/doc/ok/.confini | 1+
Mtests/test_export.py | 9+++++++++
5 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/confini/env.py b/confini/env.py @@ -30,7 +30,11 @@ class ConfigEnvParser: if len(l) == 0: break (k, v) = l.split('=') - (ks, ko) = k.split('_', maxsplit=1) + try: + (ks, ko) = k.split('_', maxsplit=1) + except ValueError: + ks = k + ko = '_' ks = ks.lower() ko = ko.lower() v = v.rstrip() diff --git a/confini/export.py b/confini/export.py @@ -54,6 +54,14 @@ class ConfigExporter: def export_section(self, ks, w): + if self.make_doc: + try: + v = self.doc.get(ks, '_') + w.write("# " + v + "\n") + except KeyError: + logg.warning('doc missing for section {}'.format(ks)) + pass + w.write("[" + ks + "]\n") for ko in self.sections[ks].keys(): if self.make_doc: diff --git a/tests/files/.confini b/tests/files/.confini @@ -1,2 +1,3 @@ +FOO=head of foo FOO_BAR=bar of foo XYZZY_BERT=bert of xyzzy diff --git a/tests/files/doc/ok/.confini b/tests/files/doc/ok/.confini @@ -1,2 +1,3 @@ +FOO=head of foo FOO_BAR=foo of bar BAR_XYZZY=bar of xyzzy diff --git a/tests/test_export.py b/tests/test_export.py @@ -110,10 +110,19 @@ class TestExport(unittest.TestCase): w.seek(0) s = w.read() + print(s) re_c = re.compile('^# ', re.MULTILINE) m = re_c.finditer(s) next(m) next(m) + next(m) + with self.assertRaises(StopIteration): + next(m) + + re_c = re.compile('^# .*foo$', re.MULTILINE) + m = re_c.finditer(s) + next(m) + next(m) with self.assertRaises(StopIteration): next(m)