Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 240ff81

Browse files
ksundenQuLogic
authored andcommitted
Merge pull request #26689 from anntzer/pgferr
Fix error generation for missing pgf.texsystem. (cherry picked from commit 5f785e3)
1 parent d75d3a2 commit 240ff81

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

lib/matplotlib/backends/backend_pgf.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -286,24 +286,14 @@ def __init__(self):
286286
self._finalize_tmpdir = weakref.finalize(self, self._tmpdir.cleanup)
287287

288288
# test the LaTeX setup to ensure a clean startup of the subprocess
289-
try:
290-
self._setup_latex_process(expect_reply=False)
291-
except FileNotFoundError as err:
292-
raise RuntimeError(
293-
f"{self.latex.args[0]!r} not found. Install it or change "
294-
f"rcParams['pgf.texsystem'] to an available TeX "
295-
f"implementation.") from err
296-
except OSError as err:
297-
raise RuntimeError(
298-
f"Error starting process {self.latex.args[0]!r}") from err
289+
self._setup_latex_process(expect_reply=False)
299290
stdout, stderr = self.latex.communicate("\n\\makeatletter\\@@end\n")
300291
if self.latex.returncode != 0:
301292
raise LatexError(
302293
f"LaTeX errored (probably missing font or error in preamble) "
303294
f"while processing the following input:\n"
304295
f"{self._build_latex_header()}",
305296
stdout)
306-
307297
self.latex = None # Will be set up on first use.
308298
# Per-instance cache.
309299
self._get_box_metrics = functools.lru_cache()(self._get_box_metrics)
@@ -318,10 +308,19 @@ def _setup_latex_process(self, *, expect_reply=True):
318308
# Windows, we must ensure that the subprocess has quit before being
319309
# able to delete the tmpdir in which it runs; in order to do so, we
320310
# must first `kill()` it, and then `communicate()` with it.
321-
self.latex = subprocess.Popen(
322-
[mpl.rcParams["pgf.texsystem"], "-halt-on-error"],
323-
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
324-
encoding="utf-8", cwd=self.tmpdir)
311+
try:
312+
self.latex = subprocess.Popen(
313+
[mpl.rcParams["pgf.texsystem"], "-halt-on-error"],
314+
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
315+
encoding="utf-8", cwd=self.tmpdir)
316+
except FileNotFoundError as err:
317+
raise RuntimeError(
318+
f"{mpl.rcParams['pgf.texsystem']!r} not found; install it or change "
319+
f"rcParams['pgf.texsystem'] to an available TeX implementation"
320+
) from err
321+
except OSError as err:
322+
raise RuntimeError(
323+
f"Error starting {mpl.rcParams['pgf.texsystem']!r}") from err
325324

326325
def finalize_latex(latex):
327326
latex.kill()

0 commit comments

Comments
 (0)