2323import functools
2424import hashlib
2525import logging
26- import os
2726from pathlib import Path
2827import subprocess
2928from tempfile import TemporaryDirectory
@@ -63,7 +62,7 @@ class TexManager:
6362 Repeated calls to this constructor always return the same instance.
6463 """
6564
66- _texcache = os . path . join (mpl .get_cachedir (),'tex.cache' )
65+ _texcache = Path (mpl .get_cachedir (),'tex.cache' )
6766_grey_arrayd = {}
6867
6968_font_families = ('serif' ,'sans-serif' ,'cursive' ,'monospace' )
@@ -109,7 +108,7 @@ class TexManager:
109108
110109@functools .lru_cache # Always return the same instance.
111110def __new__ (cls ):
112- Path ( cls ._texcache ) .mkdir (parents = True ,exist_ok = True )
111+ cls ._texcache .mkdir (parents = True ,exist_ok = True )
113112return object .__new__ (cls )
114113
115114@classmethod
@@ -176,14 +175,14 @@ def get_basefile(cls, tex, fontsize, dpi=None):
176175src .encode ('utf-8' ),
177176usedforsecurity = False
178177 ).hexdigest ()
179- filepath = Path ( cls ._texcache )
178+ filepath = cls ._texcache
180179
181180num_letters ,num_levels = 2 ,2
182181for i in range (0 ,num_letters * num_levels ,num_letters ):
183182filepath = filepath / Path (filehash [i :i + 2 ])
184183
185184filepath .mkdir (parents = True ,exist_ok = True )
186- return os . path . join (filepath , filehash )
185+ return str (filepath / filehash )
187186
188187@classmethod
189188def get_font_preamble (cls ):
@@ -312,7 +311,6 @@ def make_png(cls, tex, fontsize, dpi):
312311 Return the file name.
313312 """
314313pngfile = Path (cls .get_basefile (tex ,fontsize )).with_suffix (".png" )
315- # see get_rgba for a discussion of the background
316314if not pngfile .exists ():
317315dvifile = cls .make_dvi (tex ,fontsize )
318316with TemporaryDirectory (dir = pngfile .parent )as tmpdir :
@@ -338,7 +336,7 @@ def get_grey(cls, tex, fontsize=None, dpi=None):
338336alpha = cls ._grey_arrayd .get (key )
339337if alpha is None :
340338pngfile = cls .make_png (tex ,fontsize ,dpi )
341- rgba = mpl .image .imread (os . path . join ( cls . _texcache , pngfile ) )
339+ rgba = mpl .image .imread (pngfile )
342340cls ._grey_arrayd [key ]= alpha = rgba [:, :,- 1 ]
343341return alpha
344342