start implementing build (still failing)
This commit is contained in:
parent
41a7eb2c20
commit
dd65ab626b
4 changed files with 66 additions and 5 deletions
|
@ -1,9 +1,13 @@
|
|||
from pathlib import Path
|
||||
from typing import Optional, Union
|
||||
from typing import Optional, Union, List
|
||||
|
||||
from .enums import PyTeXRootDirType
|
||||
from .pytex_config import PyTeXConfig
|
||||
from ...logger import logger
|
||||
from .constants import *
|
||||
from ..versioning.version_info.version_info import FileVersionInfo
|
||||
from .pytex_file import PyTeXSourceFile
|
||||
from .relative_path import RelativePath
|
||||
|
||||
|
||||
class PyTeXBuilder:
|
||||
|
@ -22,23 +26,35 @@ class PyTeXBuilder:
|
|||
self._pytex_config: Optional[PyTeXConfig] = pytex_config
|
||||
self._root_dir: Optional[Path] = root_dir
|
||||
|
||||
# Non-public attributes
|
||||
self._version_info: Optional[FileVersionInfo] = None
|
||||
self._pytex_files: Optional[List[PyTeXSourceFile]] = None
|
||||
|
||||
def build_tex_sources(self):
|
||||
self._build_target_type = PyTeXRootDirType.TEX_SOURCE
|
||||
pass
|
||||
self._build()
|
||||
|
||||
def build_documentation(self):
|
||||
self._build_target_type = PyTeXRootDirType.DOC
|
||||
pass
|
||||
self._build()
|
||||
|
||||
def build_tex_files(self):
|
||||
self._build_target_type = PyTeXRootDirType.BUILD
|
||||
pass
|
||||
self._build()
|
||||
|
||||
def build(self):
|
||||
if self._build_target_type is None:
|
||||
raise NotImplementedError
|
||||
self._build()
|
||||
|
||||
@property
|
||||
def version_info(self):
|
||||
if self._version_info is None:
|
||||
self._version_info = FileVersionInfo.from_json(
|
||||
self.target_root / VERSION_INFO_FILE
|
||||
)
|
||||
return self._version_info
|
||||
|
||||
@property
|
||||
def pytex_config(self) -> PyTeXConfig:
|
||||
if self._pytex_config is None:
|
||||
|
@ -68,5 +84,46 @@ class PyTeXBuilder:
|
|||
def parse_config_file(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def supported_extensions(cls) -> List[str]:
|
||||
return [
|
||||
'.sty.pytex',
|
||||
'.cls.pytex',
|
||||
'.dtx.pytex',
|
||||
'.dict.pytex',
|
||||
'.tex.pytex',
|
||||
'.sty',
|
||||
'.cls',
|
||||
'.dtx',
|
||||
'.dict',
|
||||
'.tex',
|
||||
]
|
||||
|
||||
def is_supported_file(self, filename: str) -> bool:
|
||||
return True in [
|
||||
filename.endswith(extension)
|
||||
for extension in self.supported_extensions()
|
||||
]
|
||||
|
||||
def load_pytex_files(self):
|
||||
self._pytex_files = []
|
||||
if self.pytex_config.recursive:
|
||||
files = self.source_root.rglob('*')
|
||||
else:
|
||||
files = self.source_root.glob('*')
|
||||
for file in files:
|
||||
if self.is_supported_file(file.name):
|
||||
self._pytex_files.append(
|
||||
PyTeXSourceFile(
|
||||
relative_path=RelativePath(
|
||||
file,
|
||||
root_dir=self.source_root
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def _build(self):
|
||||
logger.info("Starting build")
|
||||
self.load_pytex_files()
|
||||
raise NotImplementedError
|
||||
|
||||
|
|
|
@ -12,3 +12,5 @@ YAML_BUILD = 'build'
|
|||
YAML_DEFAULT = 'default'
|
||||
YAML_CONFIGS = 'configs'
|
||||
YAML_DIRS = 'dirs'
|
||||
|
||||
VERSION_INFO_FILE = 'version_info.json'
|
||||
|
|
|
@ -38,7 +38,7 @@ class PyTeXSourceFile:
|
|||
|
||||
@property
|
||||
def output_files(self) -> List[RelativePath]:
|
||||
files = self._formatter.output_files
|
||||
files = self.formatter.output_files
|
||||
files = [
|
||||
self._relative_path.with_name(filename)
|
||||
for filename in files
|
||||
|
|
2
main.py
2
main.py
|
@ -51,4 +51,6 @@ pytex_config = PyTeXConfig.from_yaml(conf_path)
|
|||
|
||||
builder = PyTeXBuilder(conf_path)
|
||||
|
||||
builder.build_tex_sources()
|
||||
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue