39
39
40
40
import copy
41
41
import glob
42
+ import hashlib
43
+ import logging
42
44
import os
45
+ from pathlib import Path
43
46
import shutil
44
47
import sys
45
48
import warnings
46
- import logging
47
-
48
- from hashlib import md5
49
49
50
50
import distutils .version
51
51
import numpy as np
52
52
import matplotlib as mpl
53
53
from matplotlib import rcParams
54
54
from matplotlib ._png import read_png
55
- from matplotlib .cbook import mkdirs , Locked
55
+ from matplotlib .cbook import Locked
56
56
from matplotlib .compat .subprocess import subprocess , Popen , PIPE , STDOUT
57
57
import matplotlib .dviread as dviread
58
58
import re
@@ -88,7 +88,7 @@ class TexManager(object):
88
88
cachedir = mpl .get_cachedir ()
89
89
if cachedir is not None :
90
90
texcache = os .path .join (cachedir , 'tex.cache' )
91
- mkdirs (texcache )
91
+ Path (texcache ). mkdir ( parents = True , exist_ok = True )
92
92
else :
93
93
# Should only happen in a restricted environment (such as Google App
94
94
# Engine). Deal with this gracefully by not creating a cache directory.
@@ -136,7 +136,7 @@ def __init__(self):
136
136
raise RuntimeError ('Cannot create TexManager, as there is no '
137
137
'cache directory available' )
138
138
139
- mkdirs (self .texcache )
139
+ Path (self .texcache ). mkdir ( parents = True , exist_ok = True )
140
140
ff = rcParams ['font.family' ]
141
141
if len (ff ) == 1 and ff [0 ].lower () in self .font_families :
142
142
self .font_family = ff [0 ].lower ()
@@ -171,7 +171,7 @@ def __init__(self):
171
171
# correct png is selected for strings rendered with same font and dpi
172
172
# even if the latex preamble changes within the session
173
173
preamble_bytes = self .get_custom_preamble ().encode ('utf-8' )
174
- fontconfig .append (md5 (preamble_bytes ).hexdigest ())
174
+ fontconfig .append (hashlib . md5 (preamble_bytes ).hexdigest ())
175
175
self ._fontconfig = '' .join (fontconfig )
176
176
177
177
# The following packages and commands need to be included in the latex
@@ -188,7 +188,8 @@ def get_basefile(self, tex, fontsize, dpi=None):
188
188
"""
189
189
s = '' .join ([tex , self .get_font_config (), '%f' % fontsize ,
190
190
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 ())
192
193
193
194
def get_font_config (self ):
194
195
"""Reinitializes self if relevant rcParams on have changed."""
0 commit comments