31
31
import numpy as np
32
32
33
33
import matplotlib as mpl
34
- from matplotlib import cbook , dviread
34
+ from matplotlib import _api , cbook , dviread
35
35
36
36
_log = logging .getLogger (__name__ )
37
37
@@ -57,10 +57,14 @@ class TexManager:
57
57
"""
58
58
Convert strings to dvi files using TeX, caching the results to a directory.
59
59
60
+ The cache directory is called ``tex.cache`` and is located is the directory
61
+ returned by `.get_cachedir`.
62
+
60
63
Repeated calls to this constructor always return the same instance.
61
64
"""
62
65
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' )
64
68
_grey_arrayd = {}
65
69
66
70
_font_families = ('serif' , 'sans-serif' , 'cursive' , 'monospace' )
@@ -102,7 +106,7 @@ class TexManager:
102
106
103
107
@functools .lru_cache # Always return the same instance.
104
108
def __new__ (cls ):
105
- Path (cls .texcache ).mkdir (parents = True , exist_ok = True )
109
+ Path (cls ._texcache ).mkdir (parents = True , exist_ok = True )
106
110
return object .__new__ (cls )
107
111
108
112
@classmethod
@@ -168,7 +172,7 @@ def get_basefile(cls, tex, fontsize, dpi=None):
168
172
"""
169
173
src = cls ._get_tex_source (tex , fontsize ) + str (dpi )
170
174
filehash = hashlib .md5 (src .encode ('utf-8' )).hexdigest ()
171
- filepath = Path (cls .texcache )
175
+ filepath = Path (cls ._texcache )
172
176
173
177
num_letters , num_levels = 2 , 2
174
178
for i in range (0 , num_letters * num_levels , num_letters ):
@@ -244,7 +248,7 @@ def _run_checked_subprocess(cls, command, tex, *, cwd=None):
244
248
_log .debug (cbook ._pformat_subprocess (command ))
245
249
try :
246
250
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 ,
248
252
stderr = subprocess .STDOUT )
249
253
except FileNotFoundError as exc :
250
254
raise RuntimeError (
@@ -330,7 +334,7 @@ def get_grey(cls, tex, fontsize=None, dpi=None):
330
334
alpha = cls ._grey_arrayd .get (key )
331
335
if alpha is None :
332
336
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 ))
334
338
cls ._grey_arrayd [key ] = alpha = rgba [:, :, - 1 ]
335
339
return alpha
336
340
0 commit comments