fix writing to json and yaml

This commit is contained in:
Maximilian Keßler 2022-02-07 00:04:31 +01:00
parent d37fbe1c76
commit fb9a6a8471
2 changed files with 22 additions and 29 deletions

View file

@ -78,8 +78,9 @@ class FormattingConfig(Config):
config.set_from_json(content)
return config
def to_yaml(self) -> str:
pass
def dump_as_yaml(self, filename: Path):
with filename.open('w') as file:
yaml.dump(self.to_json(), file)
def to_json(self) -> Dict:
return {
@ -88,33 +89,33 @@ class FormattingConfig(Config):
YAML_NAMING_SCHEME: self._naming_scheme,
YAML_TEX_FLAVOUR: self._tex_flavour,
YAML_TEX_TYPE: self._tex_type,
YAML_VERSION: self._version
YAML_VERSION: self._version,
YAML_DESCRIPTION: self._description
},
YAML_HEADER: {
YAML_EXTRA: {
YAML_INCLUDE_EXTRA_HEADER: self._include_extra_header,
YAML_PATH: self._extra_header.path,
YAML_TEXT: self._extra_header.real_text
YAML_PATH: self._extra_header.path if self._extra_header else None,
YAML_TEXT: self._extra_header.real_text if self._extra_header else None
},
YAML_REPO: {
YAML_INCLUDE_INFO_TEXT: self._include_repo_info_text,
YAML_INCLUDE_VERSION: self._include_repo_version,
YAML_PATH: self._repo_info_text.path,
YAML_TEXT: self._repo_info_text.real_text
YAML_PATH: self._repo_info_text.path if self._repo_info_text else None,
YAML_TEXT: self._repo_info_text.real_text if self._repo_info_text else None
},
YAML_PYTEX: {
YAML_INCLUDE_INFO_TEXT: self._include_pytex_info_text,
YAML_INCLUDE_VERSION: self._include_pytex_version,
YAML_PATH: self._pytex_info_text.path,
YAML_TEXT: self._pytex_info_text.real_text
YAML_PATH: self._pytex_info_text.path if self._pytex_info_text else None,
YAML_TEXT: self._pytex_info_text.real_text if self._pytex_info_text else None
},
YAML_INCLUDE_TIME: self._include_time,
YAML_LICENSE: {
YAML_INCLUDE_LICENSE: self._include_license,
YAML_PATH: self._license.path,
YAML_TEXT: self._license.real_text
YAML_PATH: self._license.path if self._license else None,
YAML_TEXT: self._license.real_text if self._license else None
},
YAML_DESCRIPTION: self._description
},
YAML_DOCSTRIP: {
YAML_INCLUDE_DRV: self._include_drv,
@ -127,7 +128,6 @@ class FormattingConfig(Config):
}
}
@property
def naming_scheme(self) -> NamingScheme:
if self._naming_scheme is None:
@ -161,17 +161,6 @@ class FormattingConfig(Config):
def include_extra_header(self, include: bool):
self._include_extra_header = include
@property
def include_build_time(self) -> bool:
if self._include_build_time is None:
return False
else:
return self._include_build_time
@include_build_time.setter
def include_build_time(self, include: bool):
self._include_build_time = include
@property
def include_pytex_version(self) -> bool:
if self._include_pytex_version is None:

14
main.py
View file

@ -48,9 +48,13 @@ d2 = {
d3 = d1 | d2
print(p)
config: FormattingConfig = FormattingConfig()
config._naming_scheme = 'test'
n = config.naming_scheme
dump = config.to_json()
config.dump_as_yaml(Path('test.yaml'))
config.naming_scheme = 'prepend-author'