From 3e6f2f99c35fd51b204b4005a4276ea765d1243d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Wed, 9 Feb 2022 18:02:41 +0100 Subject: [PATCH] rework format method to support multiple output files --- PyTeX/format/simple_tex_formatter.py | 7 ------- PyTeX/format/tex_formatter.py | 23 ++++++++++++++--------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/PyTeX/format/simple_tex_formatter.py b/PyTeX/format/simple_tex_formatter.py index 81f5a87..e8ccc8b 100644 --- a/PyTeX/format/simple_tex_formatter.py +++ b/PyTeX/format/simple_tex_formatter.py @@ -14,13 +14,6 @@ class SimpleTeXFormatter(TexFormatter): } return self.name + switcher[self.config.tex_type] - def open_output_stream(self, build_dir: Path): - out_file = build_dir / self.output_file - if out_file.exists(): - raise NotImplementedError - else: - self._output_file = out_file.open('w') - def close_output_stream(self): self._output_file.close() diff --git a/PyTeX/format/tex_formatter.py b/PyTeX/format/tex_formatter.py index 01299f7..6deb74b 100644 --- a/PyTeX/format/tex_formatter.py +++ b/PyTeX/format/tex_formatter.py @@ -62,12 +62,16 @@ class TexFormatter(PyTeXFormatter, ABC): self._macros: List[Macro] = [] self._line_stream: Optional[LineStream] = None - @abstractmethod - def open_output_stream(self, build_dir: Path) -> None: + def open_output_stream(self, build_dir: Path, filename: str) -> None: """ - :param build_dir: Where to open output stream + :param filename: Name of file """ + out_file = build_dir / filename + if out_file.exists(): + raise NotImplementedError + else: + self._output_file = out_file.open('w') @abstractmethod def close_output_stream(self) -> None: @@ -151,10 +155,11 @@ class TexFormatter(PyTeXFormatter, ABC): )) def format(self, build_dir: Path, overwrite: bool = False) -> List[Tuple[str, FormattingConfig]]: - self.open_output_stream(build_dir) - self.format_pre_header() - self.format_header() - self.format_post_header() - self.format_document() - self.close_output_stream() + for filename in self.output_files: + self.open_output_stream(build_dir, filename) + self.format_pre_header() + self.format_header() + self.format_post_header() + self.format_document() + self.close_output_stream() return self.future_config