fix some bugs, more type annotations
This commit is contained in:
parent
92e69a0d77
commit
3571d409f0
5 changed files with 14 additions and 55 deletions
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -75,8 +75,8 @@ class TexFormatter(PyTeXFormatter, ABC):
|
|||
:return:
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
@property
|
||||
@abstractmethod
|
||||
def future_config(self) -> List[Tuple[str, FormattingConfig]]:
|
||||
"""
|
||||
# TODO
|
||||
|
|
48
main.py
48
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
|
||||
|
|
Loading…
Reference in a new issue