3939
4040import copy
4141import glob
42+ import hashlib
43+ import logging
4244import os
45+ from pathlib import Path
4346import shutil
4447import sys
4548import warnings
46- import logging
47-
48- from hashlib import md5
4949
5050import distutils .version
5151import numpy as np
5252import matplotlib as mpl
5353from matplotlib import rcParams
5454from matplotlib ._png import read_png
55- from matplotlib .cbook import mkdirs , Locked
55+ from matplotlib .cbook import Locked
5656from matplotlib .compat .subprocess import subprocess , Popen , PIPE , STDOUT
5757import matplotlib .dviread as dviread
5858import re
@@ -88,7 +88,7 @@ class TexManager(object):
8888 cachedir = mpl .get_cachedir ()
8989 if cachedir is not None :
9090 texcache = os .path .join (cachedir , 'tex.cache' )
91- mkdirs (texcache )
91+ Path (texcache ). mkdir ( parents = True , exist_ok = True )
9292 else :
9393 # Should only happen in a restricted environment (such as Google App
9494 # Engine). Deal with this gracefully by not creating a cache directory.
@@ -136,7 +136,7 @@ def __init__(self):
136136 raise RuntimeError ('Cannot create TexManager, as there is no '
137137 'cache directory available' )
138138
139- mkdirs (self .texcache )
139+ Path (self .texcache ). mkdir ( parents = True , exist_ok = True )
140140 ff = rcParams ['font.family' ]
141141 if len (ff ) == 1 and ff [0 ].lower () in self .font_families :
142142 self .font_family = ff [0 ].lower ()
@@ -171,7 +171,7 @@ def __init__(self):
171171 # correct png is selected for strings rendered with same font and dpi
172172 # even if the latex preamble changes within the session
173173 preamble_bytes = self .get_custom_preamble ().encode ('utf-8' )
174- fontconfig .append (md5 (preamble_bytes ).hexdigest ())
174+ fontconfig .append (hashlib . md5 (preamble_bytes ).hexdigest ())
175175 self ._fontconfig = '' .join (fontconfig )
176176
177177 # The following packages and commands need to be included in the latex
@@ -188,7 +188,8 @@ def get_basefile(self, tex, fontsize, dpi=None):
188188 """
189189 s = '' .join ([tex , self .get_font_config (), '%f' % fontsize ,
190190 self .get_custom_preamble (), str (dpi or '' )])
191- return os .path .join (self .texcache , md5 (s .encode ('utf-8' )).hexdigest ())
191+ return os .path .join (
192+ self .texcache , hashlib .md5 (s .encode ('utf-8' )).hexdigest ())
192193
193194 def get_font_config (self ):
194195 """Reinitializes self if relevant rcParams on have changed."""
0 commit comments