simplify config before dumping

This commit is contained in:
Maximilian Keßler 2022-02-07 00:21:16 +01:00
parent fb9a6a8471
commit 9d68c5cd9f
2 changed files with 19 additions and 2 deletions

View file

@ -30,6 +30,18 @@ class VersionInfo:
return self._repo_version
def clean_dict(dictionary: Dict) -> Optional[Dict]:
aux = {
k: clean_dict(v) for k, v in dictionary.items() if type(v) == dict
} | {
k: v for k, v in dictionary.items() if type(v) != dict
}
aux2 = {
k: v for k, v in aux.items() if v is not None
}
return aux2 if aux2 != {} else None
class FormattingConfig(Config):
def __init__(self):
self._naming_scheme: Optional[Union[NamingScheme, str]] = None
@ -80,7 +92,11 @@ class FormattingConfig(Config):
def dump_as_yaml(self, filename: Path):
with filename.open('w') as file:
yaml.dump(self.to_json(), file)
simple_dict = clean_dict(self.to_json())
if simple_dict is not None:
yaml.dump(simple_dict, file)
else:
pass # TODO
def to_json(self) -> Dict:
return {

View file

@ -53,8 +53,9 @@ config: FormattingConfig = FormattingConfig()
dump = config.to_json()
config.naming_scheme = 'prepend-author'
config.dump_as_yaml(Path('test.yaml'))
config.naming_scheme = 'prepend-author'