Skip to content

Commit

Permalink
do not fail on sub config
Browse files Browse the repository at this point in the history
  • Loading branch information
deadc0de6 committed Oct 24, 2024
1 parent 370e093 commit 77b7045
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions dotdrop/cfg_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class CfgYaml:

def __init__(self, path, profile=None, addprofiles=None,
reloading=False, debug=False, imported_configs=None,
fail_on_missing_keys=True):
fail_on_error=True):
"""
config parser
@path: config file path
Expand Down Expand Up @@ -169,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, fail_on_missing_keys)
self._validate(self._yaml_dict, fail_on_error)

##################################################
# parse the config and variables
Expand Down Expand Up @@ -1082,7 +1082,7 @@ def _import_config(self, path):
addprofiles=self._inc_profiles,
debug=self._debug,
imported_configs=self.imported_configs,
fail_on_missing_keys=False)
fail_on_error=False)

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

def _validate(self, yamldict, fail_on_missing_key):
def _validate(self, yamldict, fail_on_error):
"""validate entries"""
if not yamldict:
raise YamlException('empty config file')
if fail_on_error:
raise YamlException('empty config file')
return

# check top entries
for entry in self.top_entries:
Expand All @@ -1354,10 +1356,14 @@ def _validate(self, yamldict, fail_on_missing_key):
# check link_dotfile_default
if self.key_settings not in yamldict:
# no configs top entry
raise YamlException(f'no \"{self.key_settings}\" key found')
if fail_on_missing_key and not yamldict[self.key_settings]:
if fail_on_error:
raise YamlException(f'no \"{self.key_settings}\" key found')
return
if not yamldict[self.key_settings]:
# configs empty
raise YamlException(f'empty \"{self.key_settings}\" key')
if fail_on_error:
raise YamlException(f'empty \"{self.key_settings}\" key')
return

# check settings values
settings = yamldict[self.key_settings]
Expand Down

0 comments on commit 77b7045

Please sign in to comment.