fix bugs in docstrip formatter

This commit is contained in:
Maximilian Keßler 2022-02-18 23:45:55 +01:00
parent df423f586f
commit 9f732688d9
2 changed files with 33 additions and 11 deletions

View file

@ -63,9 +63,26 @@ class PyTeXBuilder:
)
return version
@classmethod
def is_ignored_in_build_dir(cls, path: RelativePath):
return path.relative_path.name == VERSION_INFO_FILE
def _ignored_subfolders_in_build_dir(self) -> List[Path]:
if self._build_target_type == PyTeXRootDirType.BUILD:
dirs = [
self.pytex_config.build_dir_specification.tex_source_root,
self.pytex_config.build_dir_specification.doc_root
]
return [
path.absolute().resolve() for path in dirs
]
return []
def is_ignored_in_build_dir(self, path: RelativePath) -> bool:
real_path: Path = path.absolute().resolve()
ignored_dirs = self._ignored_subfolders_in_build_dir()
for ignored_dir in ignored_dirs:
if ignored_dir in real_path.parents:
return True
return path.relative_path.name in [
VERSION_INFO_FILE, '.pytexrc'
]
def build_tex_sources(self) -> bool:
self._build_target_type = PyTeXRootDirType.TEX_SOURCE

View file

@ -1,5 +1,5 @@
import tempfile
import os
from .enums import TeXType
from .formatting_config import FormattingConfig
from .pytex_formatter import PyTeXFormatter
@ -15,9 +15,9 @@ class DocStripFormatter(PyTeXFormatter):
@property
def output_files(self) -> List[str]:
if self.config.tex_out_type == TeXType.TeXClass:
return self.name + '.cls'
elif self.config.tex_out_type == TeXType.TeXClass:
return self.name + '.sty'
return [self.raw_name + '.cls']
elif self.config.tex_out_type == TeXType.TeXPackage:
return [self.raw_name + '.sty']
else:
raise NotImplementedError
@ -28,13 +28,18 @@ class DocStripFormatter(PyTeXFormatter):
tmp_dir
)
if self.input_file.with_suffix('.ins').exists():
shutil.copy(
self.input_file.with_suffix('.ins'),
tmp_dir
)
result = subprocess.run(
['tex', self.input_file.with_suffix('.ins').name],
["tex", self.input_file.with_suffix('.ins').name],
cwd=tmp_dir,
stderr=subprocess.STDOUT
stderr=subprocess.DEVNULL, # TODO
stdout=subprocess.DEVNULL # TODO
)
if not result.returncode == 0:
raise NotImplementedError
raise NotImplementedError('no correct returncode')
else:
result = subprocess.run(
['pdflatex', self.input_file.name],
@ -46,7 +51,7 @@ class DocStripFormatter(PyTeXFormatter):
for file in self.output_files:
outfile = tmp_dir / file
if not outfile.exists():
raise NotImplementedError
raise NotImplementedError(f'output file {outfile} does not exist')
shutil.copy(outfile, build_dir)
shutil.rmtree(tmp_dir)
return [] # No future config