From 5ede703131254b569a22644d9ce3ca43329813f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 6 Feb 2022 15:10:28 +0100 Subject: [PATCH] start pytex formatter --- PyTeX/format/formatterif.py | 57 +++++++++++++++++++++++++++++++++ PyTeX/format/pytex_formatter.py | 39 ++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 PyTeX/format/formatterif.py create mode 100644 PyTeX/format/pytex_formatter.py diff --git a/PyTeX/format/formatterif.py b/PyTeX/format/formatterif.py new file mode 100644 index 0000000..dcce840 --- /dev/null +++ b/PyTeX/format/formatterif.py @@ -0,0 +1,57 @@ +from typing import List, Optional, Dict, Tuple +from pathlib import Path + + +class Config: + pass + + +class FormatterIF: + """ + A formatter is bound to a specific input file with some + building configuration. + """ + def __init__( + self, + input_file: Optional[Path] = None, + config: Optional[Config] = None, + ): + self._input_file: Optional[Path] = input_file + self._config: Optional[Config] = config + + def format(self, build_dir: Path) -> Optional[List[Tuple[str, Dict]]]: + """ + :param build_dir: Directory where output files are written to + :return: When configuration files are needed for a future + build of the output files, a list of the file names and their + needed configurations. Else None. + """ + pass + + @property + def output_files(self) -> List[str]: + """ + + :return: List of files that will be built when the formatter is invoked + """ + pass + + @property + def input_file(self) -> Path: + if self._input_file is None: + raise NotImplementedError + return self._input_file + + @input_file.setter + def input_file(self, input_file: Path) -> None: + self._input_file = input_file + + @property + def config(self) -> Config: + if self._config is None: + raise NotImplementedError + return self._config + + @config.setter + def config(self, config: Config): + self._config = config diff --git a/PyTeX/format/pytex_formatter.py b/PyTeX/format/pytex_formatter.py new file mode 100644 index 0000000..51b57ec --- /dev/null +++ b/PyTeX/format/pytex_formatter.py @@ -0,0 +1,39 @@ +from pathlib import Path +from typing import Optional, List +from .formatting_config import FormattingConfig +from .enums import TeXType, TeXFlavour +from .formatterif import FormatterIF +from .generic_text import GenericText + +class PyTeXFormatter(FormatterIF): + def __init__( + self, + input_file: Optional[Path] = None, + config: Optional[FormattingConfig] = None, + tex_type: Optional[TeXType] = None, + tex_flavour: Optional[TeXFlavour] = None + ): + super().__init__( + input_file=input_file, + config=config + ) + self._config: Optional[FormattingConfig] = self._config + self._tex_type: Optional[TeXType] = tex_type + self._tex_flavour: Optional[TeXFlavour] = tex_flavour + self._header: Optional[GenericText] = None + self._formatted_header: Optional[str] = None + + @property + def config(self) -> FormattingConfig: + if self._config is None: + raise NotImplementedError + return self._config + + @property + def header(self) -> GenericText: + if self._header is None: + if not( + self.config.include_extra_header + or self.config.include_build_time + ): + pass