diff --git a/patacrep/build.py b/patacrep/build.py index 2fb134fb..d260d45b 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -164,7 +164,6 @@ class SongbookBuilder(object): def _set_latex(self): """Set LaTeX options.""" - self._lualatex_options.append("--file-line-error") if self.unsafe: self._lualatex_options.append("--shell-escape") if not self.interactive: @@ -218,25 +217,32 @@ class SongbookBuilder(object): LOGGER.info("Building '{}.pdf'…".format(self.basename)) 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: process = Popen( - ["lualatex"] + self._lualatex_options + [self.basename], + [compiler] + self._lualatex_options + [self.basename], stdin=PIPE, stdout=PIPE, stderr=PIPE, env=os.environ, - cwd=os.getcwd(), universal_newlines=True, ) except Exception as 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) if not self.interactive: diff --git a/patacrep/errors.py b/patacrep/errors.py index d48f8e1f..d1d3a74f 100644 --- a/patacrep/errors.py +++ b/patacrep/errors.py @@ -31,6 +31,16 @@ class TemplateError(SongbookError): else: 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): """Error during execution of one compilation step.""" diff --git a/test/test_compilation/test_compilation.py b/test/test_compilation/test_compilation.py index d98b5211..efb6ebe4 100644 --- a/test/test_compilation/test_compilation.py +++ b/test/test_compilation/test_compilation.py @@ -121,7 +121,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): command, stderr=subprocess.STDOUT, universal_newlines=True, - cwd=os.path.dirname(songbook) + cwd=os.path.dirname(songbook), ) return 0 except subprocess.CalledProcessError as error: