pytex/PyTeX/build/pytex_file/pytex_file.py

42 lines
1.3 KiB
Python

from typing import Optional, List, Dict, Tuple, Union
from pathlib import Path
from .enums import PyTeXFileType
from PyTeX.format.formatterif import FormatterIF
from PyTeX.build.paths import RelativePath
class PyTeXSourceFile:
def __init__(self):
self._pytex_file_type: PyTeXFileType = None
self._relative_path: RelativePath = None
self._formatter: FormatterIF = None
@property
def relative_path(self):
return self._relative_path
@property
def pytex_file_type(self) -> PyTeXFileType:
return self._pytex_file_type
@property
def output_files(self) -> List[RelativePath]:
files = self._formatter.output_files
files = [
self._relative_path.with_name(filename)
for filename in files
]
return files
def format(self, target_root: Union[Path, RelativePath]) -> Optional[List[Tuple[RelativePath, Dict]]]:
try:
configs = self._formatter.format(
target_root.path if isinstance(target_root, RelativePath) else target_root
)
except Exception as e:
raise NotImplementedError
configs = [
(self._relative_path.with_name(filename), config)
for [filename, config] in configs
]
return configs