8000 Deprecate backend_pgf.LatexManagerFactory. · matplotlib/matplotlib@c87c26d · GitHub
[go: up one dir, main page]

Skip to content

Commit c87c26d

Browse files
committed
Deprecate backend_pgf.LatexManagerFactory.
It's an optimization helper that can just as well be implemented privately using lru_cache.
1 parent 1e2fea7 commit c87c26d

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-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: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def __init__(self, message, latex_output=""):
187187
self.latex_output = latex_output
188188

189189

190+
@cbook.deprecated("3.1")
190191
class LatexManagerFactory:
191192
previous_instance = None
192193

@@ -223,14 +224,31 @@ def _build_latex_header():
223224
# Create LaTeX header with some content, else LaTeX will load some math
224225
# fonts later when we don't expect the additional output on stdout.
225226
# 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}"]
227+
latex_header = [
228+
# Include TeX program name as a comment for cache invalidation.
229+
r"% !TeX program = {}".format(rcParams["pgf.texsystem"]),
230+
r"\documentclass{minimal}",
231+
latex_preamble,
232+
latex_fontspec,
233+
r"\begin{document}",
234+
r"text $math \mu$", # force latex to load fonts now
235+
r"\typeout{pgf_backend_query_start}",
236+
]
232237
return "\n".join(latex_header)
233238

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

390408
# get LatexManager instance
391-
self.latexManager = LatexManagerFactory.get_latex_manager()
409+
self.latexManager = LatexManager._get_cached_or_new()
392410

393411
if dummy:
394412
# dummy==True deactivate all methods

0 commit comments

Comments
 (0)
0