Skip to content

Commit

Permalink
fix sub config import error
Browse files Browse the repository at this point in the history
  • Loading branch information
deadc0de6 committed Oct 24, 2024
1 parent adc0ab5 commit 370e093
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions dotdrop/cfg_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class CfgYaml:
top_entries = [key_dotfiles, key_settings, key_profiles]

def __init__(self, path, profile=None, addprofiles=None,
reloading=False, debug=False, imported_configs=None):
reloading=False, debug=False, imported_configs=None,
fail_on_missing_keys=True):
"""
config parser
@path: config file path
Expand Down Expand Up @@ -168,7 +169,7 @@ def __init__(self, path, profile=None, addprofiles=None,
# live patch deprecated entries
self._fix_deprecated(self._yaml_dict)
# validate content
self._validate(self._yaml_dict)
self._validate(self._yaml_dict, fail_on_missing_keys)

##################################################
# parse the config and variables
Expand Down Expand Up @@ -1080,7 +1081,8 @@ def _import_config(self, path):
sub = CfgYaml(path, profile=self._profile,
addprofiles=self._inc_profiles,
debug=self._debug,
imported_configs=self.imported_configs)
imported_configs=self.imported_configs,
fail_on_missing_keys=False)

# settings are ignored from external file
# except for filter_file and func_file
Expand Down Expand Up @@ -1337,7 +1339,7 @@ def _load_yaml(self, path):
self._dbg(f'format: {self._config_format}')
return content

def _validate(self, yamldict):
def _validate(self, yamldict, fail_on_missing_key):
"""validate entries"""
if not yamldict:
raise YamlException('empty config file')
Expand All @@ -1353,7 +1355,7 @@ def _validate(self, yamldict):
if self.key_settings not in yamldict:
# no configs top entry
raise YamlException(f'no \"{self.key_settings}\" key found')
if not yamldict[self.key_settings]:
if fail_on_missing_key and not yamldict[self.key_settings]:
# configs empty
raise YamlException(f'empty \"{self.key_settings}\" key')

Expand Down

0 comments on commit 370e093

Please sign in to comment.