From 97bc1fd50f90305c8b312cdd21e9eaa51e504122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 18 Feb 2022 21:20:32 +0100 Subject: [PATCH] divide config into two parts --- PyTeX/build/build/build_dir_spec.py | 15 +++++++---- PyTeX/build/build/builder.py | 7 +++++ PyTeX/format/tex_formatter.py | 40 ++++++++++++++--------------- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/PyTeX/build/build/build_dir_spec.py b/PyTeX/build/build/build_dir_spec.py index 2a4605f..7ec8fa2 100644 --- a/PyTeX/build/build/build_dir_spec.py +++ b/PyTeX/build/build/build_dir_spec.py @@ -23,11 +23,16 @@ class BuildDirConfig(Config): def set_from_json(self, content: Optional[Dict]): filled_content = self._fill_keys(content) - self._tex_source_root = Path(filled_content[YAML_TEX_SOURCE_ROOT]) - self._pytex_source_root = Path(filled_content[YAML_PYTEX_SOURCE_ROOT]) - self._build_root = Path(filled_content[YAML_BUILD_ROOT]) - self._doc_root = Path(filled_content[YAML_DOC_ROOT]) - self._wrapper_dir = Path(filled_content[YAML_WRAPPER_DIR]) + self._tex_source_root = Path(filled_content[YAML_TEX_SOURCE_ROOT]) \ + if filled_content[YAML_TEX_SOURCE_ROOT] else None + self._pytex_source_root = Path(filled_content[YAML_PYTEX_SOURCE_ROOT]) \ + if filled_content[YAML_PYTEX_SOURCE_ROOT] else None + self._build_root = Path(filled_content[YAML_BUILD_ROOT]) \ + if filled_content[YAML_BUILD_ROOT] else None + self._doc_root = Path(filled_content[YAML_DOC_ROOT]) \ + if filled_content[YAML_DOC_ROOT] else None + self._wrapper_dir = Path(filled_content[YAML_WRAPPER_DIR]) \ + if filled_content[YAML_WRAPPER_DIR] else None def to_json(self) -> Dict: return { diff --git a/PyTeX/build/build/builder.py b/PyTeX/build/build/builder.py index 3d7f1a5..59a37a0 100644 --- a/PyTeX/build/build/builder.py +++ b/PyTeX/build/build/builder.py @@ -83,6 +83,12 @@ class PyTeXBuilder: raise NotImplementedError return self._build() + def _update_config_in_input_folder(self): + config_file = self.source_root / '.pytexrc' # TODO + if config_file.exists(): + config = PyTeXConfig.from_yaml(config_file) + self._pytex_config = config.merge_with(self.pytex_config) + @property def old_version_info(self) -> VersionInfo: if self._old_version_info is None: @@ -304,6 +310,7 @@ class PyTeXBuilder: self._new_version_info.dump_as_json(self.target_root / VERSION_INFO_FILE) def _build(self) -> bool: + self._update_config_in_input_folder() logger.info("Starting build") self._load_pytex_files() # 8ms logger.verbose(f"Found {len(self._pytex_files)} source files") diff --git a/PyTeX/format/tex_formatter.py b/PyTeX/format/tex_formatter.py index 62f89ba..f057a54 100644 --- a/PyTeX/format/tex_formatter.py +++ b/PyTeX/format/tex_formatter.py @@ -168,27 +168,25 @@ class TexFormatter(PyTeXFormatter, ABC): self._mode = mode def _get_provides_text(self, provided_type: str) -> str: - if self.config.has_description: - if self.config.tex_flavour == TeXFlavour.LaTeX2e: - return \ - r'\Provides%s{%s}[%s - %s]' \ - % ( - provided_type, - self.name, - self.attribute_dict[FormatterProperty.date.value], - self.attribute_dict[FormatterProperty.description.value] - ) - - else: - return \ - '\\ProvidesExpl%s { %s } { %s } { %s }\n { %s }' \ - % ( - provided_type, - self.name, - self.attribute_dict[FormatterProperty.date.value], - self.config.version, - self.config.description - ) + if self.config.tex_flavour == TeXFlavour.LaTeX2e: + return \ + r'\Provides%s{%s}[%s - %s]' \ + % ( + provided_type, + self.name, + self.attribute_dict[FormatterProperty.date.value], + self.attribute_dict[FormatterProperty.description.value] + ) + else: + return \ + '\\ProvidesExpl%s { %s } { %s } { %s }\n { %s }' \ + % ( + provided_type, + self.name, + self.attribute_dict[FormatterProperty.date.value], + self.config.version, + self.config.description + ) def format_header(self): if self._output_file is None: