implement methods of pytexSourceFile class

This commit is contained in:
Maximilian Keßler 2022-02-05 18:51:44 +01:00
parent f4e133b3e5
commit 8df045c457
2 changed files with 38 additions and 9 deletions

View file

@ -1,28 +1,40 @@
from typing import Optional, List from typing import Optional, List, Dict, Tuple
from PyTeX.build.build_info import BasicBuildInfo from PyTeX.build.build_info import BasicBuildInfo
from PyTeX.config import BasicFormattingConfig, GlobalPyTeXConfig from PyTeX.config import BasicFormattingConfig, GlobalPyTeXConfig
from PyTeX.paths import RelativePath
from .enums import PyTeXFileType from .enums import PyTeXFileType
from PyTeX.formatting.formatter import Formatter
from ...paths import RelativePath
class PyTeXSourceFile: class PyTeXSourceFile:
def __init__(self): def __init__(self):
self._pytex_file_type: PyTeXFileType = None self._pytex_file_type: PyTeXFileType = None
self._relative_path: RelativePath = None self._relative_path: RelativePath = None
self._formatter: Formatter = None
self._build_info: Optional[BasicBuildInfo] = None self._build_info: Optional[BasicBuildInfo] = None
@property @property
def relative_path(self) -> RelativePath: def relative_path(self):
return self._relative_path return self._relative_path
@property @property
def pytex_file_type(self) -> PyTeXFileType: def pytex_file_type(self) -> PyTeXFileType:
return self._pytex_file_type return self._pytex_file_type
def format(self) -> None:
pass
@property @property
def provided_files(self) -> List[RelativePath]: def output_files(self) -> List[RelativePath]:
pass 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]]]:
configs = self._formatter.format(GlobalPyTeXConfig.target_root())
configs = [
(self._relative_path.with_name(filename), config)
for [filename, config] in configs
]
return configs

View file

@ -2,6 +2,8 @@ from pathlib import Path, PurePath
from typing import Optional from typing import Optional
from .formatting_config import BasicFormattingConfig from .formatting_config import BasicFormattingConfig
from ..paths import PyTeXRootDirType
class GlobalPyTeXConfig: class GlobalPyTeXConfig:
_source_root: Optional[Path] = None _source_root: Optional[Path] = None
@ -18,6 +20,8 @@ class GlobalPyTeXConfig:
_allow_dirty: bool = False _allow_dirty: bool = False
_build_target: PyTeXRootDirType = None
@classmethod @classmethod
def init( def init(
cls, cls,
@ -51,4 +55,17 @@ class GlobalPyTeXConfig:
@classmethod @classmethod
def wrapper_dir(cls) -> PurePath: def wrapper_dir(cls) -> PurePath:
return cls._wrapper_dir raise NotImplementedError
@classmethod
def build_mode(cls) -> PyTeXRootDirType:
return cls._build_target
@classmethod
def target_root(cls) -> Path:
return {
PyTeXRootDirType.BUILD: cls.build_root(),
PyTeXRootDirType.DOC: cls.doc_root(),
PyTeXRootDirType.TEX_SOURCE: cls.tex_root(),
PyTeXRootDirType.PYTEX_SOURCE: cls.source_root()
}[cls._build_target]