Browse Source

Cleanly check if the LaTeX compiler is present

pull/139/head
Oliverpool 9 years ago
parent
commit
8d34114bd2
  1. 26
      patacrep/build.py
  2. 10
      patacrep/errors.py
  3. 2
      test/test_compilation/test_compilation.py

26
patacrep/build.py

@ -164,7 +164,6 @@ class SongbookBuilder(object):
def _set_latex(self): def _set_latex(self):
"""Set LaTeX options.""" """Set LaTeX options."""
self._lualatex_options.append("--file-line-error")
if self.unsafe: if self.unsafe:
self._lualatex_options.append("--shell-escape") self._lualatex_options.append("--shell-escape")
if not self.interactive: if not self.interactive:
@ -218,25 +217,32 @@ class SongbookBuilder(object):
LOGGER.info("Building '{}.pdf'".format(self.basename)) LOGGER.info("Building '{}.pdf'".format(self.basename))
self._run_once(self._set_latex) self._run_once(self._set_latex)
compiler = "lualatex"
# test if the LaTeX compiler is accessible
try:
process = Popen(
[compiler, "--version"],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
env=os.environ,
universal_newlines=True,
)
except Exception as error:
raise errors.ExecutableNotFound(compiler)
try: try:
process = Popen( process = Popen(
["lualatex"] + self._lualatex_options + [self.basename], [compiler] + self._lualatex_options + [self.basename],
stdin=PIPE, stdin=PIPE,
stdout=PIPE, stdout=PIPE,
stderr=PIPE, stderr=PIPE,
env=os.environ, env=os.environ,
cwd=os.getcwd(),
universal_newlines=True, universal_newlines=True,
) )
except Exception as error: except Exception as error:
LOGGER.debug(error) LOGGER.debug(error)
LOGGER.debug(os.getcwd())
import subprocess
LOGGER.debug(subprocess.check_output(
['dir', os.getcwd()],
stderr=subprocess.STDOUT,
universal_newlines=True
))
raise errors.LatexCompilationError(self.basename) raise errors.LatexCompilationError(self.basename)
if not self.interactive: if not self.interactive:

10
patacrep/errors.py

@ -31,6 +31,16 @@ class TemplateError(SongbookError):
else: else:
return self.message return self.message
class ExecutableNotFound(SongbookError):
"""Couldn't find a LaTeX executable."""
def __init__(self, executable):
super(ExecutableNotFound, self).__init__(
(
"""Could not find the following executable: {executable}"""
).format(executable=executable)
)
class StepError(SongbookError): class StepError(SongbookError):
"""Error during execution of one compilation step.""" """Error during execution of one compilation step."""

2
test/test_compilation/test_compilation.py

@ -121,7 +121,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
command, command,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
universal_newlines=True, universal_newlines=True,
cwd=os.path.dirname(songbook) cwd=os.path.dirname(songbook),
) )
return 0 return 0
except subprocess.CalledProcessError as error: except subprocess.CalledProcessError as error:

Loading…
Cancel
Save