From 76a2de4d6e2e06827b78e330545460ea451ac12f Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Fri, 27 Oct 2023 21:09:05 +0200 Subject: [PATCH] improve TinyTeX call --- rendercv/rendering.py | 44 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/rendercv/rendering.py b/rendercv/rendering.py index fb5880a..f836a8c 100644 --- a/rendercv/rendering.py +++ b/rendercv/rendering.py @@ -428,24 +428,32 @@ def run_latex(latex_file_path: str) -> str: " RenderCV again." ) - try: - subprocess.run( - [ - executable, - f"{latex_file_name}", - ], - cwd=os.path.dirname(latex_file_path), - check=True, - stdout=subprocess.DEVNULL, # suppress latexmk output - timeout=45, - ) - except subprocess.CalledProcessError or subprocess.TimeoutExpired as e: - raise RuntimeError( - "Running TinyTeX has failed with the following error:\n\ncommand" - f' "{e.cmd}" return with error (code {e.returncode}): {e.output}\n\nIf' - " you can't find the problem, please try to re-install RenderCV, or open" - " an issue on GitHub." - ) + # Run TinyTeX: + with subprocess.Popen( + [ + executable, + f"{latex_file_name}", + ], + cwd=os.path.dirname(latex_file_path), + stdout=subprocess.PIPE, + stdin=subprocess.DEVNULL, # don't allow TinyTeX to ask for user input + text=True, + ) as latex_process: + output, error = latex_process.communicate() + output.split("\n") + + if latex_process.returncode != 0: + # Find the error line: + for line in output.split("\n"): + if line.startswith("! "): + error_line = line.replace("! ", "") + break + + raise RuntimeError( + "Running TinyTeX has failed with the following error:\n\n" + f"{error_line}\n\nIf you can't solve the problem, please try to" + " re-install RenderCV, or open an issue on GitHub." + ) # check if the PDF file is generated: if not os.path.exists(output_file_path):