From fb9a6a84711b5eb650c65cdb22ca35aeaff79306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Mon, 7 Feb 2022 00:04:31 +0100 Subject: [PATCH] fix writing to json and yaml --- PyTeX/format/formatting_config.py | 37 +++++++++++-------------------- main.py | 14 +++++++----- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/PyTeX/format/formatting_config.py b/PyTeX/format/formatting_config.py index fd1b40d..8388e09 100644 --- a/PyTeX/format/formatting_config.py +++ b/PyTeX/format/formatting_config.py @@ -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: diff --git a/main.py b/main.py index f5805de..9bc5d86 100644 --- a/main.py +++ b/main.py @@ -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' +