fix error when building from dtx files
wait for subprocess to complete catch some more errors
This commit is contained in:
parent
e661ceee64
commit
ed6494826f
4 changed files with 37 additions and 9 deletions
|
@ -148,7 +148,7 @@ def build(
|
|||
elif not str(file.relative_to(output_dir)) in built_files:
|
||||
if not file.is_dir() and not str(file.relative_to(output_dir)) == 'build_info.json':
|
||||
# PyTeX does not at all know something about this file
|
||||
raise UnknownFileInBuildDirectory(file.relative_to(output_dir))
|
||||
raise UnknownFileInBuildDirectoryError(file.relative_to(output_dir))
|
||||
|
||||
if write_build_information:
|
||||
with open(output_dir / 'build_info.json', 'w') as f:
|
||||
|
|
|
@ -4,6 +4,7 @@ import subprocess
|
|||
|
||||
from PyTeX.formatter import Formatter
|
||||
from PyTeX.utils import ensure_file_integrity
|
||||
from PyTeX.errors import FileNotGeneratedFromDTXFileError, LatexMKError
|
||||
|
||||
|
||||
class DocstripFormatter(Formatter):
|
||||
|
@ -19,13 +20,20 @@ class DocstripFormatter(Formatter):
|
|||
relative_name: Optional[str] = None,
|
||||
last_build_info: Optional[List[Dict]] = None) -> List[str]:
|
||||
ensure_file_integrity(output_dir / self.filename, str(Path(relative_name).parent / self.filename), last_build_info)
|
||||
result = subprocess.Popen(['pdflatex', self.name + '.dtx'], cwd=str(input_path.parent),
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
try:
|
||||
result = subprocess.run(['latexmk', '-gg', '-output-directory=/tmp'], cwd=str(input_path.parent),
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
except subprocess.CalledProcessError:
|
||||
raise LatexMKError(self.filename)
|
||||
if not result:
|
||||
pass
|
||||
sty = input_path.with_suffix('.sty').read_text()
|
||||
sty_file = (Path('/tmp') / input_path.with_suffix('.sty').name)
|
||||
if sty_file.exists():
|
||||
sty = sty_file.read_text()
|
||||
else:
|
||||
raise FileNotGeneratedFromDTXFileError(self.filename, 'style')
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
(output_dir / self.filename).write_text(sty)
|
||||
return [self.filename]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from .errors import PyTexError, SubmoduleDirtyForbiddenError, ProgrammingError, ExtraHeaderFileNotFoundError, \
|
||||
UnknownTexVersionError, ModifiedFileInBuildDirectoryError, UnknownFileInBuildDirectoryNoOverwriteError, \
|
||||
UnknownFileInBuildDirectory
|
||||
UnknownFileInBuildDirectoryError, LatexMKError, FileNotGeneratedFromDTXFileError
|
||||
|
||||
__all__ = [
|
||||
'PyTexError',
|
||||
|
@ -10,5 +10,7 @@ __all__ = [
|
|||
'UnknownTexVersionError',
|
||||
'ModifiedFileInBuildDirectoryError',
|
||||
'UnknownFileInBuildDirectoryNoOverwriteError',
|
||||
'UnknownFileInBuildDirectory'
|
||||
'UnknownFileInBuildDirectoryError',
|
||||
'LatexMKError',
|
||||
'FileNotGeneratedFromDTXFileError'
|
||||
]
|
||||
|
|
|
@ -56,10 +56,28 @@ class UnknownFileInBuildDirectoryNoOverwriteError(PyTexError):
|
|||
)
|
||||
|
||||
|
||||
class UnknownFileInBuildDirectory(PyTexError):
|
||||
class UnknownFileInBuildDirectoryError(PyTexError):
|
||||
def __init__(self, filename):
|
||||
super().__init__(
|
||||
f"Detected unknown file {filename} in build directory."
|
||||
f"PyTeX has no knowledge about this, you should probably"
|
||||
f"remove it."
|
||||
)
|
||||
|
||||
|
||||
class LatexMKError(PyTexError):
|
||||
def __init__(self, filename):
|
||||
super().__init__(
|
||||
f"Running latexmk on file {filename} resulted in an error. "
|
||||
f"Make sure this file is well-formed and an appropriate "
|
||||
f"'.latexmkrc' is present in its directory."
|
||||
)
|
||||
|
||||
|
||||
class FileNotGeneratedFromDTXFileError(PyTexError):
|
||||
def __init__(self, filename, type):
|
||||
super().__init__(
|
||||
f"Running latexmk on {filename} did not produce a LaTeX "
|
||||
f"{type} file as needed. I do not know how to build "
|
||||
f"a {type} from this '.dtx' file."
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue