fix some small bugs: main building mechanism now working

This commit is contained in:
Maximilian Keßler 2022-02-09 00:13:34 +01:00
parent ec26ec232f
commit 1bcd6040fb
2 changed files with 28 additions and 14 deletions

View file

@ -1,5 +1,6 @@
from pathlib import Path from pathlib import Path
from typing import Optional, Union, List, Tuple, Set from typing import Optional, Union, List, Tuple, Set
import shutil
from .enums import PyTeXRootDirType from .enums import PyTeXRootDirType
from .pytex_config import PyTeXConfig from .pytex_config import PyTeXConfig
@ -173,11 +174,12 @@ class PyTeXBuilder:
raise NotImplementedError # what to do in this case? dependency does not exist... raise NotImplementedError # what to do in this case? dependency does not exist...
def _check_output_directory_integrity(self): def _check_output_directory_integrity(self):
out_dir_files = [ out_dir_files: List[RelativePath] = [
RelativePath(self.target_root, file) RelativePath(self.target_root, file)
for file in self.target_root.rglob('*') for file in self.target_root.rglob('*')
] ]
for file in out_dir_files: for file in out_dir_files:
if not file.relative_path.is_dir():
version = self._old_version_lookup(file) version = self._old_version_lookup(file)
if version.file_hash != md5(file.path): if version.file_hash != md5(file.path):
if self.pytex_config.clean_old_files: if self.pytex_config.clean_old_files:
@ -222,11 +224,22 @@ class PyTeXBuilder:
def _build_files(self): def _build_files(self):
for source_file in self._files_to_build: for source_file in self._files_to_build:
import os
out_dir = self._tmp_dir / source_file.file_hash out_dir = self._tmp_dir / source_file.file_hash
out_dir.mkdir(exist_ok=False, parents=True) out_dir.mkdir(exist_ok=False, parents=True)
source_file.format(self._tmp_dir / source_file.file_hash) source_file.format(self._tmp_dir / source_file.file_hash)
def _move_files(self):
for source_file in self._files_to_build:
tmp_dir = self._tmp_dir / source_file.file_hash
for filename in source_file.output_files:
out_dir = self.target_root / source_file.relative_path.relative_path.parent
out_dir.mkdir(parents=True, exist_ok=True)
shutil.move(
tmp_dir / filename.relative_path.name,
out_dir / filename.relative_path.name
)
shutil.rmtree(self._tmp_dir)
def _build(self) -> bool: def _build(self) -> bool:
logger.info("Starting build") logger.info("Starting build")
self._load_pytex_files() self._load_pytex_files()
@ -238,4 +251,5 @@ class PyTeXBuilder:
self._check_output_directory_integrity() self._check_output_directory_integrity()
logger.info(f"Starting build") logger.info(f"Starting build")
self._build_files() self._build_files()
self._move_files()
return True return True

View file

@ -53,7 +53,7 @@ class PyTeXSourceFile:
raise NotImplementedError # TODO raise NotImplementedError # TODO
files: List[str] = self._formatter.output_files files: List[str] = self._formatter.output_files
paths = [ paths = [
self._relative_path.with_name(filename) RelativePath(self._relative_path.root_dir, self._relative_path.with_name(filename))
for filename in files for filename in files
] ]
return paths return paths