Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 28123a1

Browse filesBrowse files
committed
Deduplicate common parts in LatexManager.{__init__,_setup_latex_process}
1 parent 2716c82 commit 28123a1
Copy full SHA for 28123a1

File tree

Expand file treeCollapse file tree

2 files changed

+20
-19
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-19
lines changed
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The ``texcommand`` and ``latex_header`` attributes of ``backend_pgf.LatexManager``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... are deprecated.

‎lib/matplotlib/backends/backend_pgf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pgf.py
+17-19Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -291,43 +291,41 @@ def __init__(self):
291291
self._finalize_tmpdir = weakref.finalize(self, self._tmpdir.cleanup)
292292

293293
# test the LaTeX setup to ensure a clean startup of the subprocess
294-
self.texcommand = mpl.rcParams["pgf.texsystem"]
295-
self.latex_header = LatexManager._build_latex_header()
296-
latex_end = "\n\\makeatletter\n\\@@end\n"
297294
try:
298-
latex = subprocess.Popen(
299-
[self.texcommand, "-halt-on-error"],
300-
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
301-
encoding="utf-8", cwd=self.tmpdir)
295+
self._setup_latex_process(expect_reply=False)
302296
except FileNotFoundError as err:
303297
raise RuntimeError(
304-
f"{self.texcommand} not found. Install it or change "
298+
f"{self.latex.args[0]!r} not found. Install it or change "
305299
f"rcParams['pgf.texsystem'] to an available TeX "
306300
f"implementation.") from err
307301
except OSError as err:
308-
raise RuntimeError("Error starting process %r" %
309-
self.texcommand) from err
310-
test_input = self.latex_header + latex_end
311-
stdout, stderr = latex.communicate(test_input)
312-
if latex.returncode != 0:
302+
raise RuntimeError(
303+
f"Error starting process {self.latex.args[0]!r}") from err
304+
stdout, stderr = self.latex.communicate("\n\\makeatletter\\@@end\n")
305+
if self.latex.returncode != 0:
313306
raise LatexError(
314307
f"LaTeX errored (probably missing font or error in preamble) "
315-
f"while processing the following input:\n{test_input}",
308+
f"while processing the following input:\n"
309+
f"{self._build_latex_header()}",
316310
stdout)
317311

318312
self.latex = None # Will be set up on first use.
319313
# Per-instance cache.
320314
self._get_box_metrics = functools.lru_cache()(self._get_box_metrics)
321315

322316
str_cache = _api.deprecated("3.5")(property(lambda self: {}))
317+
texcommand = _api.deprecated("3.6")(
318+
property(lambda self: mpl.rcParams["pgf.texsystem"]))
319+
latex_header = _api.deprecated("3.6")(
320+
property(lambda self: self._build_latex_header()))
323321

324-
def _setup_latex_process(self):
322+
def _setup_latex_process(self, *, expect_reply=True):
325323
# Open LaTeX process for real work; register it for deletion. On
326324
# Windows, we must ensure that the subprocess has quit before being
327325
# able to delete the tmpdir in which it runs; in order to do so, we
328326
# must first `kill()` it, and then `communicate()` with it.
329327
self.latex = subprocess.Popen(
330-
[self.texcommand, "-halt-on-error"],
328+
[mpl.rcParams["pgf.texsystem"], "-halt-on-error"],
331329
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
332330
encoding="utf-8", cwd=self.tmpdir)
333331

@@ -339,9 +337,9 @@ def finalize_latex(latex):
339337
self, finalize_latex, self.latex)
340338
# write header with 'pgf_backend_query_start' token
341339
self._stdin_writeln(self._build_latex_header())
342-
# read all lines until our 'pgf_backend_query_start' token appears
343-
self._expect("*pgf_backend_query_start")
344-
self._expect_prompt()
340+
if expect_reply: # read until 'pgf_backend_query_start' token appears
341+
self._expect("*pgf_backend_query_start")
342+
self._expect_prompt()
345343

346344
def get_width_height_descent(self, text, prop):
347345
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.