23
23
import functools
24
24
import hashlib
25
25
import logging
26
- import os
27
26
from pathlib import Path
28
27
import subprocess
29
28
from tempfile import TemporaryDirectory
@@ -63,7 +62,7 @@ class TexManager:
63
62
Repeated calls to this constructor always return the same instance.
64
63
"""
65
64
66
- _texcache = os . path . join (mpl .get_cachedir (), 'tex.cache' )
65
+ _texcache = Path (mpl .get_cachedir (), 'tex.cache' )
67
66
_grey_arrayd = {}
68
67
69
68
_font_families = ('serif' , 'sans-serif' , 'cursive' , 'monospace' )
@@ -109,7 +108,7 @@ class TexManager:
109
108
110
109
@functools .lru_cache # Always return the same instance.
111
110
def __new__ (cls ):
112
- Path ( cls ._texcache ) .mkdir (parents = True , exist_ok = True )
111
+ cls ._texcache .mkdir (parents = True , exist_ok = True )
113
112
return object .__new__ (cls )
114
113
115
114
@classmethod
@@ -176,14 +175,14 @@ def get_basefile(cls, tex, fontsize, dpi=None):
176
175
src .encode ('utf-8' ),
177
176
usedforsecurity = False
178
177
).hexdigest ()
179
- filepath = Path ( cls ._texcache )
178
+ filepath = cls ._texcache
180
179
181
180
num_letters , num_levels = 2 , 2
182
181
for i in range (0 , num_letters * num_levels , num_letters ):
183
182
filepath = filepath / Path (filehash [i :i + 2 ])
184
183
185
184
filepath .mkdir (parents = True , exist_ok = True )
186
- return os . path . join (filepath , filehash )
185
+ return str (filepath / filehash )
187
186
188
187
@classmethod
189
188
def get_font_preamble (cls ):
@@ -312,7 +311,6 @@ def make_png(cls, tex, fontsize, dpi):
312
311
Return the file name.
313
312
"""
314
313
pngfile = Path (cls .get_basefile (tex , fontsize )).with_suffix (".png" )
315
- # see get_rgba for a discussion of the background
316
314
if not pngfile .exists ():
317
315
dvifile = cls .make_dvi (tex , fontsize )
318
316
with TemporaryDirectory (dir = pngfile .parent ) as tmpdir :
@@ -338,7 +336,7 @@ def get_grey(cls, tex, fontsize=None, dpi=None):
338
336
alpha = cls ._grey_arrayd .get (key )
339
337
if alpha is None :
340
338
pngfile = cls .make_png (tex , fontsize , dpi )
341
- rgba = mpl .image .imread (os . path . join ( cls . _texcache , pngfile ) )
339
+ rgba = mpl .image .imread (pngfile )
342
340
cls ._grey_arrayd [key ] = alpha = rgba [:, :, - 1 ]
343
341
return alpha
344
342
0 commit comments