3131import numpy as np
3232
3333import matplotlib as mpl
34- from matplotlib import cbook , dviread
34+ from matplotlib import _api , cbook , dviread
3535
3636_log = logging .getLogger (__name__ )
3737
@@ -57,10 +57,14 @@ class TexManager:
5757 """
5858 Convert strings to dvi files using TeX, caching the results to a directory.
5959
60+ The cache directory is called ``tex.cache`` and is located in the directory
61+ returned by `.get_cachedir`.
62+
6063 Repeated calls to this constructor always return the same instance.
6164 """
6265
63- texcache = os .path .join (mpl .get_cachedir (), 'tex.cache' )
66+ texcache = _api .deprecate_privatize_attribute ("3.8" )
67+ _texcache = os .path .join (mpl .get_cachedir (), 'tex.cache' )
6468 _grey_arrayd = {}
6569
6670 _font_families = ('serif' , 'sans-serif' , 'cursive' , 'monospace' )
@@ -102,7 +106,7 @@ class TexManager:
102106
103107 @functools .lru_cache # Always return the same instance.
104108 def __new__ (cls ):
105- Path (cls .texcache ).mkdir (parents = True , exist_ok = True )
109+ Path (cls ._texcache ).mkdir (parents = True , exist_ok = True )
106110 return object .__new__ (cls )
107111
108112 @classmethod
@@ -168,7 +172,7 @@ def get_basefile(cls, tex, fontsize, dpi=None):
168172 """
169173 src = cls ._get_tex_source (tex , fontsize ) + str (dpi )
170174 filehash = hashlib .md5 (src .encode ('utf-8' )).hexdigest ()
171- filepath = Path (cls .texcache )
175+ filepath = Path (cls ._texcache )
172176
173177 num_letters , num_levels = 2 , 2
174178 for i in range (0 , num_letters * num_levels , num_letters ):
@@ -244,7 +248,7 @@ def _run_checked_subprocess(cls, command, tex, *, cwd=None):
244248 _log .debug (cbook ._pformat_subprocess (command ))
245249 try :
246250 report = subprocess .check_output (
247- command , cwd = cwd if cwd is not None else cls .texcache ,
251+ command , cwd = cwd if cwd is not None else cls ._texcache ,
248252 stderr = subprocess .STDOUT )
249253 except FileNotFoundError as exc :
250254 raise RuntimeError (
@@ -330,7 +334,7 @@ def get_grey(cls, tex, fontsize=None, dpi=None):
330334 alpha = cls ._grey_arrayd .get (key )
331335 if alpha is None :
332336 pngfile = cls .make_png (tex , fontsize , dpi )
333- rgba = mpl .image .imread (os .path .join (cls .texcache , pngfile ))
337+ rgba = mpl .image .imread (os .path .join (cls ._texcache , pngfile ))
334338 cls ._grey_arrayd [key ] = alpha = rgba [:, :, - 1 ]
335339 return alpha
336340
0 commit comments