integrate git version info into formatters

This commit is contained in:
Maximilian Keßler 2022-02-09 14:08:51 +01:00
parent c3b4a87b51
commit 7b689255bc
4 changed files with 11 additions and 4 deletions

View file

@ -162,7 +162,8 @@ class PyTeXBuilder:
self.source_root,
file
),
default_config=self.pytex_config.default_formatting_config
default_config=self.pytex_config.default_formatting_config,
git_version_info=self._git_version_info
)
)

View file

@ -7,6 +7,7 @@ from PyTeX.build.build.enums import PyTeXFileType
from .hashing import md5
from ...format.formatting_config import FormattingConfig
from ...format.auto_format import formatter_from_file_extension
from ...format.git_version_info import GitVersionInfo
class PyTeXSourceFile:
@ -15,6 +16,7 @@ class PyTeXSourceFile:
relative_path: RelativePath,
formatter: Optional[FormatterIF] = None,
default_config: Optional[FormattingConfig] = None,
git_version_info: Optional[GitVersionInfo] = None,
pytex_file_type: Optional[PyTeXFileType] = None
):
self._relative_path: RelativePath = relative_path
@ -24,6 +26,7 @@ class PyTeXSourceFile:
self._formatter = formatter_from_file_extension(
relative_path.path,
config=default_config,
git_version_info=git_version_info,
locate_file_config=True,
allow_infile_config=True
)

View file

@ -7,11 +7,13 @@ from .dict_formatter import DictFormatter
from .simple_tex_formatter import SimpleTeXFormatter
from .dtx_formatter import DTXFormatter
from .pytex_formatter import PyTeXFormatter
from .git_version_info import GitVersionInfo
def formatter_from_file_extension(
input_file: Path,
config: Optional[FormattingConfig] = None,
git_version_info: Optional[GitVersionInfo] = None,
locate_file_config: bool = True,
allow_infile_config: bool = True
) -> PyTeXFormatter:
@ -30,6 +32,7 @@ def formatter_from_file_extension(
return switcher[extension](
input_file=input_file,
config=config,
git_version_info=git_version_info,
locate_file_config=locate_file_config,
allow_infile_config=allow_infile_config
)

View file

@ -5,7 +5,7 @@ from typing import Optional, Dict
from .constants import *
from .formatterif import FormatterIF
from .formatting_config import FormattingConfig
from .git_version_info import RepoStatusInfo
from .git_version_info import GitVersionInfo
from .generic_text import GenericText
from ..logger import logger
from abc import ABC
@ -16,7 +16,7 @@ class PyTeXFormatter(FormatterIF, ABC):
self,
input_file: Optional[Path] = None,
config: Optional[FormattingConfig] = None,
git_version_info: Optional[RepoStatusInfo] = None,
git_version_info: Optional[GitVersionInfo] = None,
locate_file_config: bool = True,
allow_infile_config: bool = True
):
@ -25,7 +25,7 @@ class PyTeXFormatter(FormatterIF, ABC):
config=config
)
self._config: Optional[FormattingConfig] = self._config # for type-hinting
self._git_version_info: Optional[RepoStatusInfo] = git_version_info
self._git_version_info: Optional[GitVersionInfo] = git_version_info
self._allow_infile_config: bool = allow_infile_config
self._header: Optional[GenericText] = None
if locate_file_config: