From 4ceb02f6fcab7c0ad4f366333eca634aa6c49bce Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 4 Sep 2023 07:57:44 +0200 Subject: [PATCH] Fix error generation for missing pgf.texsystem. If pgf.texsystem isn't installed, then self.latex will not be created *at all* by _setup_latex_process, and we thus cannot access self.latex.args[0], but must instead read the rc value again. To make this clearer, move the error handling into _setup_latex_process, instead of having it outside. No test because that'd require setting up a test env where pgf.texsystem is explicitly *missing* (or go through lots of mocks), which seems not worth it. --- lib/matplotlib/backends/backend_pgf.py | 29 +++++++++++++------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index 734c188b0048..ccf4b800a614 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -241,16 +241,7 @@ def __init__(self): self._finalize_tmpdir = weakref.finalize(self, self._tmpdir.cleanup) # test the LaTeX setup to ensure a clean startup of the subprocess - try: - self._setup_latex_process(expect_reply=False) - except FileNotFoundError as err: - raise RuntimeError( - f"{self.latex.args[0]!r} not found. Install it or change " - f"rcParams['pgf.texsystem'] to an available TeX " - f"implementation.") from err - except OSError as err: - raise RuntimeError( - f"Error starting process {self.latex.args[0]!r}") from err + self._setup_latex_process(expect_reply=False) stdout, stderr = self.latex.communicate("\n\\makeatletter\\@@end\n") if self.latex.returncode != 0: raise LatexError( @@ -258,7 +249,6 @@ def __init__(self): f"while processing the following input:\n" f"{self._build_latex_header()}", stdout) - self.latex = None # Will be set up on first use. # Per-instance cache. self._get_box_metrics = functools.lru_cache(self._get_box_metrics) @@ -268,10 +258,19 @@ def _setup_latex_process(self, *, expect_reply=True): # Windows, we must ensure that the subprocess has quit before being # able to delete the tmpdir in which it runs; in order to do so, we # must first `kill()` it, and then `communicate()` with it. - self.latex = subprocess.Popen( - [mpl.rcParams["pgf.texsystem"], "-halt-on-error"], - stdin=subprocess.PIPE, stdout=subprocess.PIPE, - encoding="utf-8", cwd=self.tmpdir) + try: + self.latex = subprocess.Popen( + [mpl.rcParams["pgf.texsystem"], "-halt-on-error"], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + encoding="utf-8", cwd=self.tmpdir) + except FileNotFoundError as err: + raise RuntimeError( + f"{mpl.rcParams['pgf.texsystem']!r} not found; install it or change " + f"rcParams['pgf.texsystem'] to an available TeX implementation" + ) from err + except OSError as err: + raise RuntimeError( + f"Error starting {mpl.rcParams['pgf.texsystem']!r}") from err def finalize_latex(latex): latex.kill() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy