From 3571d409f0f51bd4dc2628d904ec55fbb549d216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 8 Feb 2022 19:01:18 +0100 Subject: [PATCH] fix some bugs, more type annotations --- PyTeX/format/auto_format.py | 8 +++--- PyTeX/format/config.py | 3 ++- PyTeX/format/pytex_formatter.py | 8 +++--- PyTeX/format/tex_formatter.py | 2 +- main.py | 48 +++------------------------------ 5 files changed, 14 insertions(+), 55 deletions(-) diff --git a/PyTeX/format/auto_format.py b/PyTeX/format/auto_format.py index 522254d..0f90f88 100644 --- a/PyTeX/format/auto_format.py +++ b/PyTeX/format/auto_format.py @@ -16,10 +16,10 @@ def formatter_from_file_extension( allow_infile_config: bool = True ) -> PyTeXFormatter: switcher: Dict[str, Type[Union[DTXFormatter, SimpleTeXFormatter, DictFormatter]]] = { - '.dtx.pytex': DTXFormatter, - '.sty.pytex': SimpleTeXFormatter, - '.cls.pytex': SimpleTeXFormatter, - '.dict.pytex': DictFormatter + 'dtx.pytex': DTXFormatter, + 'sty.pytex': SimpleTeXFormatter, + 'cls.pytex': SimpleTeXFormatter, + 'dict.pytex': DictFormatter } # TODO: other formatters try: diff --git a/PyTeX/format/config.py b/PyTeX/format/config.py index 0f8c878..29c7daf 100644 --- a/PyTeX/format/config.py +++ b/PyTeX/format/config.py @@ -1,3 +1,4 @@ +from __future__ import annotations import json from pathlib import Path from typing import Dict, Optional, Union @@ -18,7 +19,7 @@ def clean_dict(dictionary: Dict) -> Optional[Dict]: class Config: - def merge_with(self, other, strict: bool = False): + def merge_with(self, other: Config, strict: bool = False): """ Merges the other config into this one :param other: diff --git a/PyTeX/format/pytex_formatter.py b/PyTeX/format/pytex_formatter.py index 920bd03..cc361d6 100644 --- a/PyTeX/format/pytex_formatter.py +++ b/PyTeX/format/pytex_formatter.py @@ -33,13 +33,13 @@ class PyTeXFormatter(FormatterIF, ABC): file_config.merge_with( infile_config, strict=True - ).merge_with(self._config, strict=False) + ).merge_with(self.config, strict=False) else: - self._config = file_config.merge_with(self._config) + self._config = file_config.merge_with(self.config) else: if allow_infile_config: infile_config = self.parse_infile_config() - self._config = infile_config.merge_with(self._config) + self._config = infile_config.merge_with(self.config) def parse_file_config(self) -> FormattingConfig: config_file = self.input_file.with_name(self.input_file.name + PYTEX_CONFIG_FILE_EXTENSION) @@ -84,7 +84,7 @@ class PyTeXFormatter(FormatterIF, ABC): @property def config(self) -> FormattingConfig: if self._config is None: - raise NotImplementedError + return FormattingConfig() return self._config @config.setter diff --git a/PyTeX/format/tex_formatter.py b/PyTeX/format/tex_formatter.py index b59be29..b7625b8 100644 --- a/PyTeX/format/tex_formatter.py +++ b/PyTeX/format/tex_formatter.py @@ -75,8 +75,8 @@ class TexFormatter(PyTeXFormatter, ABC): :return: """ - @abstractmethod @property + @abstractmethod def future_config(self) -> List[Tuple[str, FormattingConfig]]: """ # TODO diff --git a/main.py b/main.py index 91915c4..c8e423a 100644 --- a/main.py +++ b/main.py @@ -1,53 +1,9 @@ from pathlib import Path - from PyTeX.build.build import PyTeXBuilder -from PyTeX.build.build.build_dir_spec import BuildDirConfig from PyTeX.build.build.pytex_config import PyTeXConfig -from PyTeX.build.build.relative_path import RelativePath from PyTeX.format.formatting_config import FormattingConfig -spec = BuildDirConfig( - source_root=Path('src'), - tex_root=Path('build/source'), - build_root=Path('build'), - doc_root=Path('build/doc'), - wrapper_dir=Path('mkessler') -) - -p: RelativePath = RelativePath(Path('src'), 'src/hello/bla') - -rel = p.relative_path - -q = p / 'test' - -re2 = q.relative_path - -p2 = RelativePath(Path('doc'), 'build/doc/mkessler/hello/bla') - -p3 = p / p2 - -p4 = p.with_name('myname') - -d1 = { - 'a': 1, - 'b': 2 -} - -d2 = { - 'a': 3, - 'c': 4 -} - -d3 = d1 | d2 - -config: FormattingConfig = FormattingConfig() - -dump = config.to_json() - -conf_path = Path('/home/maximilian/git/LatexPackages/.pytexrc') - -pytex_config = PyTeXConfig.from_yaml(conf_path) - +conf_path = Path('.pytexrc') builder = PyTeXBuilder(conf_path) @@ -55,4 +11,6 @@ builder.build_tex_sources() v = builder.version_info + + pass