Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb1628f

Browse files
committed
Use pathlib in texmanager.
Only a few changes are needed. Note that make_png returns an absolutepath so path joining is not even needed here.Also drop an unrelated but outdated comment re: background handling,which is obsolete since 8940c66 (look for `if hack: ...`).
1 parentcae6696 commiteb1628f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

‎lib/matplotlib/texmanager.py‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
importfunctools
2424
importhashlib
2525
importlogging
26-
importos
2726
frompathlibimportPath
2827
importsubprocess
2928
fromtempfileimportTemporaryDirectory
@@ -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.
111110
def__new__(cls):
112-
Path(cls._texcache).mkdir(parents=True,exist_ok=True)
111+
cls._texcache.mkdir(parents=True,exist_ok=True)
113112
returnobject.__new__(cls)
114113

115114
@classmethod
@@ -176,14 +175,14 @@ def get_basefile(cls, tex, fontsize, dpi=None):
176175
src.encode('utf-8'),
177176
usedforsecurity=False
178177
).hexdigest()
179-
filepath=Path(cls._texcache)
178+
filepath=cls._texcache
180179

181180
num_letters,num_levels=2,2
182181
foriinrange(0,num_letters*num_levels,num_letters):
183182
filepath=filepath/Path(filehash[i:i+2])
184183

185184
filepath.mkdir(parents=True,exist_ok=True)
186-
returnos.path.join(filepath,filehash)
185+
returnstr(filepath/filehash)
187186

188187
@classmethod
189188
defget_font_preamble(cls):
@@ -312,7 +311,6 @@ def make_png(cls, tex, fontsize, dpi):
312311
Return the file name.
313312
"""
314313
pngfile=Path(cls.get_basefile(tex,fontsize)).with_suffix(".png")
315-
# see get_rgba for a discussion of the background
316314
ifnotpngfile.exists():
317315
dvifile=cls.make_dvi(tex,fontsize)
318316
withTemporaryDirectory(dir=pngfile.parent)astmpdir:
@@ -338,7 +336,7 @@ def get_grey(cls, tex, fontsize=None, dpi=None):
338336
alpha=cls._grey_arrayd.get(key)
339337
ifalphaisNone:
340338
pngfile=cls.make_png(tex,fontsize,dpi)
341-
rgba=mpl.image.imread(os.path.join(cls._texcache,pngfile))
339+
rgba=mpl.image.imread(pngfile)
342340
cls._grey_arrayd[key]=alpha=rgba[:, :,-1]
343341
returnalpha
344342

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp