fix some bugs, more type annotations

This commit is contained in:
Maximilian Keßler 2022-02-08 19:01:18 +01:00
parent 92e69a0d77
commit 3571d409f0
5 changed files with 14 additions and 55 deletions

View file

@ -16,10 +16,10 @@ def formatter_from_file_extension(
allow_infile_config: bool = True allow_infile_config: bool = True
) -> PyTeXFormatter: ) -> PyTeXFormatter:
switcher: Dict[str, Type[Union[DTXFormatter, SimpleTeXFormatter, DictFormatter]]] = { switcher: Dict[str, Type[Union[DTXFormatter, SimpleTeXFormatter, DictFormatter]]] = {
'.dtx.pytex': DTXFormatter, 'dtx.pytex': DTXFormatter,
'.sty.pytex': SimpleTeXFormatter, 'sty.pytex': SimpleTeXFormatter,
'.cls.pytex': SimpleTeXFormatter, 'cls.pytex': SimpleTeXFormatter,
'.dict.pytex': DictFormatter 'dict.pytex': DictFormatter
} }
# TODO: other formatters # TODO: other formatters
try: try:

View file

@ -1,3 +1,4 @@
from __future__ import annotations
import json import json
from pathlib import Path from pathlib import Path
from typing import Dict, Optional, Union from typing import Dict, Optional, Union
@ -18,7 +19,7 @@ def clean_dict(dictionary: Dict) -> Optional[Dict]:
class Config: 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 Merges the other config into this one
:param other: :param other:

View file

@ -33,13 +33,13 @@ class PyTeXFormatter(FormatterIF, ABC):
file_config.merge_with( file_config.merge_with(
infile_config, infile_config,
strict=True strict=True
).merge_with(self._config, strict=False) ).merge_with(self.config, strict=False)
else: else:
self._config = file_config.merge_with(self._config) self._config = file_config.merge_with(self.config)
else: else:
if allow_infile_config: if allow_infile_config:
infile_config = self.parse_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: def parse_file_config(self) -> FormattingConfig:
config_file = self.input_file.with_name(self.input_file.name + PYTEX_CONFIG_FILE_EXTENSION) config_file = self.input_file.with_name(self.input_file.name + PYTEX_CONFIG_FILE_EXTENSION)
@ -84,7 +84,7 @@ class PyTeXFormatter(FormatterIF, ABC):
@property @property
def config(self) -> FormattingConfig: def config(self) -> FormattingConfig:
if self._config is None: if self._config is None:
raise NotImplementedError return FormattingConfig()
return self._config return self._config
@config.setter @config.setter

View file

@ -75,8 +75,8 @@ class TexFormatter(PyTeXFormatter, ABC):
:return: :return:
""" """
@abstractmethod
@property @property
@abstractmethod
def future_config(self) -> List[Tuple[str, FormattingConfig]]: def future_config(self) -> List[Tuple[str, FormattingConfig]]:
""" """
# TODO # TODO

48
main.py
View file

@ -1,53 +1,9 @@
from pathlib import Path from pathlib import Path
from PyTeX.build.build import PyTeXBuilder 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.pytex_config import PyTeXConfig
from PyTeX.build.build.relative_path import RelativePath
from PyTeX.format.formatting_config import FormattingConfig from PyTeX.format.formatting_config import FormattingConfig
spec = BuildDirConfig( conf_path = Path('.pytexrc')
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)
builder = PyTeXBuilder(conf_path) builder = PyTeXBuilder(conf_path)
@ -55,4 +11,6 @@ builder.build_tex_sources()
v = builder.version_info v = builder.version_info
pass pass