improve TinyTeX call

This commit is contained in:
Sina Atalay 2023-10-27 21:09:05 +02:00
parent a21af89f08
commit 76a2de4d6e
1 changed files with 26 additions and 18 deletions

View File

@ -428,23 +428,31 @@ def run_latex(latex_file_path: str) -> str:
" RenderCV again."
)
try:
subprocess.run(
# Run TinyTeX:
with subprocess.Popen(
[
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:
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\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."
"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: