pytex/PyTeX/build/pytex_file/pytex_file.py

44 lines
1.3 KiB
Python
Raw Normal View History

from typing import Optional, List, Dict, Tuple
2022-02-04 21:14:40 +01:00
from PyTeX.build.build_info import BasicBuildInfo
from PyTeX.build.config import GlobalPyTeXConfig
2022-02-04 21:14:40 +01:00
from .enums import PyTeXFileType
from PyTeX.format.formatter import Formatter
from PyTeX.build.paths import RelativePath
2022-02-04 21:14:40 +01:00
class PyTeXSourceFile:
def __init__(self):
self._pytex_file_type: PyTeXFileType = None
self._relative_path: RelativePath = None
self._formatter: Formatter = None
2022-02-04 21:14:40 +01:00
self._build_info: Optional[BasicBuildInfo] = None
@property
def relative_path(self):
2022-02-04 21:14:40 +01:00
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) -> Optional[List[Tuple[RelativePath, Dict]]]:
2022-02-05 18:55:28 +01:00
try:
configs = self._formatter.format(GlobalPyTeXConfig.target_root())
except Exception as e:
2022-02-05 19:05:50 +01:00
raise NotImplementedError
configs = [
(self._relative_path.with_name(filename), config)
for [filename, config] in configs
]
return configs