pytex/PyTeX/build/config/global_config.py

72 lines
1.9 KiB
Python
Raw Normal View History

2022-02-04 21:14:58 +01:00
from pathlib import Path, PurePath
2022-02-04 11:39:15 +01:00
from typing import Optional
2022-02-05 19:36:42 +01:00
from PyTeX.format.formatting_config import FormattingConfig
2022-02-04 11:39:15 +01:00
2022-02-05 19:36:42 +01:00
from ..enums import PyTeXRootDirType
2022-02-04 11:39:15 +01:00
class GlobalPyTeXConfig:
_source_root: Optional[Path] = None
_build_root: Optional[Path] = None
_doc_root: Optional[Path] = None
_tex_root: Optional[Path] = None
2022-02-04 21:14:58 +01:00
_wrapper_dir: Optional[PurePath] = None
2022-02-04 11:39:15 +01:00
2022-02-05 19:36:42 +01:00
_default_formatting_config: Optional[FormattingConfig] = None
2022-02-04 11:39:15 +01:00
_recursive: bool = True
_overwrite_existing_files: bool = False
_clean_old_files: True
_allow_dirty: bool = False
_build_target: PyTeXRootDirType = None
2022-02-04 21:14:58 +01:00
@classmethod
def init(
cls,
source_root: Optional[Path] = None,
build_root: Optional[Path] = None,
doc_root: Optional[Path] = None,
tex_root: Optional[Path] = None,
wrapper_dir: Optional[PurePath] = None
):
cls._source_root = source_root
cls._build_root = build_root
cls._doc_root = doc_root
cls._tex_root = tex_root
cls._wrapper_dir = wrapper_dir
2022-02-04 11:39:15 +01:00
@classmethod
def build_root(cls) -> Path:
return cls._build_root
@classmethod
def doc_root(cls) -> Path:
return cls._doc_root
@classmethod
def source_root(cls) -> Path:
return cls._source_root
@classmethod
def tex_root(cls) -> Path:
return cls._tex_root
2022-02-04 21:14:58 +01:00
@classmethod
def wrapper_dir(cls) -> PurePath:
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]