2022-02-06 15:10:28 +01:00
|
|
|
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
|
|
|
|
|
2022-02-06 15:28:04 +01:00
|
|
|
|
2022-02-06 15:10:28 +01:00
|
|
|
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
|
2022-02-06 15:28:04 +01:00
|
|
|
or self.config.include_pytex_version
|
|
|
|
or self.config.include_pytex_info_text
|
|
|
|
or self.config.include_repo_version
|
|
|
|
or self.config.include_repo_info_text
|
2022-02-06 15:10:28 +01:00
|
|
|
):
|
2022-02-06 15:28:04 +01:00
|
|
|
self._header = GenericText([])
|
|
|
|
else:
|
|
|
|
self._header = GenericText([])
|
|
|
|
# TODO: handle license
|
|
|
|
if self.config.include_extra_header:
|
|
|
|
self._header += self.config.extra_header + ['']
|
|
|
|
if self.config.include_repo_info_text:
|
|
|
|
self._header += self.config.repo_info_text
|
|
|
|
if self.config.include_pytex_info_text:
|
|
|
|
self._header += self.config.pytex_info_text + ['']
|
|
|
|
|
|
|
|
## TODO handle rest
|
|
|
|
|
|
|
|
return self._header
|