let pytex source files auto select formatter if not given
This commit is contained in:
parent
f89ccf245b
commit
92e69a0d77
2 changed files with 14 additions and 6 deletions
|
@ -6,6 +6,7 @@ from PyTeX.format.formatterif import FormatterIF
|
|||
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
|
||||
|
||||
|
||||
class PyTeXSourceFile:
|
||||
|
@ -13,15 +14,22 @@ class PyTeXSourceFile:
|
|||
self,
|
||||
relative_path: RelativePath,
|
||||
formatter: Optional[FormatterIF] = None,
|
||||
default_config: Optional[FormattingConfig] = None,
|
||||
pytex_file_type: Optional[PyTeXFileType] = None
|
||||
):
|
||||
self._relative_path: RelativePath = relative_path
|
||||
self._pytex_file_type: Optional[PyTeXFileType] = None
|
||||
self._formatter: Optional[FormatterIF] = None
|
||||
if formatter is not None:
|
||||
self._formatter: FormatterIF = formatter
|
||||
else:
|
||||
self._formatter = formatter_from_file_extension(
|
||||
relative_path.path,
|
||||
config=default_config,
|
||||
locate_file_config=True,
|
||||
allow_infile_config=True
|
||||
)
|
||||
self._pytex_file_type: Optional[PyTeXFileType] = pytex_file_type
|
||||
self._file_hash: Optional[str] = None
|
||||
|
||||
# TODO: select formatter automatically...?
|
||||
|
||||
@property
|
||||
def file_hash(self) -> str:
|
||||
if self._file_hash is None:
|
||||
|
|
|
@ -9,8 +9,7 @@ from .dtx_formatter import DTXFormatter
|
|||
from .pytex_formatter import PyTeXFormatter
|
||||
|
||||
|
||||
def from_file_extension(
|
||||
cls,
|
||||
def formatter_from_file_extension(
|
||||
input_file: Path,
|
||||
config: Optional[FormattingConfig] = None,
|
||||
locate_file_config: bool = True,
|
||||
|
@ -22,6 +21,7 @@ def from_file_extension(
|
|||
'.cls.pytex': SimpleTeXFormatter,
|
||||
'.dict.pytex': DictFormatter
|
||||
}
|
||||
# TODO: other formatters
|
||||
try:
|
||||
[name, extension] = input_file.name.split('.', maxsplit=1)
|
||||
except:
|
||||
|
|
Loading…
Reference in a new issue