mirror of https://github.com/eyhc1/rendercv.git
improve TinyTeX call
This commit is contained in:
parent
a21af89f08
commit
76a2de4d6e
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue