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

Skip to content

Commit 6840a2f

Browse files
authored
Merge pull request #12933 from anntzer/latexmanagerfactory
Deprecate backend_pgf.LatexManagerFactory.
2 parents e8be5f7 + 0665261 commit 6840a2f

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Deprecations
2+
````````````
3+
4+
The ``backend_pgf.LatexManagerFactory`` class is deprecated.

lib/matplotlib/backends/backend_pgf.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import atexit
22
import codecs
3+
import functools
34
import logging
45
import math
56
import os
@@ -187,6 +188,7 @@ def __init__(self, message, latex_output=""):
187188
self.latex_output = latex_output
188189

189190

191+
@cbook.deprecated("3.1")
190192
class LatexManagerFactory:
191193
previous_instance = None
192194

@@ -223,14 +225,31 @@ def _build_latex_header():
223225
# Create LaTeX header with some content, else LaTeX will load some math
224226
# fonts later when we don't expect the additional output on stdout.
225227
# TODO: is this sufficient?
226-
latex_header = [r"\documentclass{minimal}",
227-
latex_preamble,
228-
latex_fontspec,
229-
r"\begin{document}",
230-
r"text $math \mu$", # force latex to load fonts now
231-
r"\typeout{pgf_backend_query_start}"]
228+
latex_header = [
229+
# Include TeX program name as a comment for cache invalidation.
230+
r"% !TeX program = {}".format(rcParams["pgf.texsystem"]),
231+
r"\documentclass{minimal}",
232+
latex_preamble,
233+
latex_fontspec,
234+
r"\begin{document}",
235+
r"text $math \mu$", # force latex to load fonts now
236+
r"\typeout{pgf_backend_query_start}",
237+
]
232238
return "\n".join(latex_header)
233239

240+
@classmethod
241+
def _get_cached_or_new(cls):
242+
"""
243+
Return the previous LatexManager if the header and tex system did not
244+
change, or a new instance otherwise.
245+
"""
246+
return cls._get_cached_or_new_impl(cls._build_latex_header())
247+
248+
@classmethod
249+
@functools.lru_cache(1)
250+
def _get_cached_or_new_impl(cls, header): # Helper for _get_cached_or_new.
251+
return cls()
252+
234253
@staticmethod
235254
def _cleanup_remaining_instances():
236255
unclean_instances = list(LatexManager._unclean_instances)
@@ -388,7 +407,7 @@ def __init__(self, figure, fh, dummy=False):
388407
self.image_counter = 0
389408

390409
# get LatexManager instance
391-
self.latexManager = LatexManagerFactory.get_latex_manager()
410+
self.latexManager = LatexManager._get_cached_or_new()
392411

393412
if dummy:
394413
# dummy==True deactivate all methods

0 commit comments

Comments
 (0)