Skip to content

Commit aa9001f

Browse files
committed
Fix issue where main section was not always created
1 parent b484c23 commit aa9001f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

conf_d/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def raw(self, section=None):
7070

7171
def parse(self):
7272
configs = self._parse_section(path=self._path, defaults=self._main_defaults, parser=self._main_parser, only_section=self._name)
73-
self._main_config = configs[self._name]
73+
self._main_config = configs.get(self._name)
7474

7575
self._config_sections = self._parse_section(path=self._path, defaults=self._section_defaults, parser=self._section_parser, remove_section=self._name)
7676
if self._confd_path:
@@ -110,4 +110,10 @@ def _parse_section(self, path, defaults={}, parser=None, only_section=None, remo
110110

111111
configs[section] = config
112112

113+
if only_section and len(configs) == 0:
114+
if hasattr(parser, '__call__'):
115+
configs[only_section] = parser(defaults)
116+
else:
117+
configs[only_section] = defaults
118+
113119
return configs

0 commit comments

Comments
 (0)