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

Commit05b5fb5

Browse files
committed
Reinstate deleted functions
With a deprecation decorator
1 parent8d90a48 commit05b5fb5

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

‎lib/matplotlib/testing/compare.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
importmatplotlib
1313
frommatplotlibimportcbook
1414
frommatplotlib.compatimportsubprocess
15+
frommatplotlib.testingimportconversion_cacheasccache
1516
frommatplotlib.testing.exceptionsimportImageComparisonFailure
1617
frommatplotlibimport_png
1718

@@ -120,6 +121,25 @@ def comparable_formats():
120121
return ['png']+list(converter)
121122

122123

124+
@cbook.deprecated('2.1',addendum='Use ConversionCache instead')
125+
defget_cache_dir():
126+
returnccache.ConversionCache.get_cache_dir()
127+
128+
129+
@cbook.deprecated('2.1',addendum='Use ConversionCache instead')
130+
defget_file_hash(path,block_size=2**20):
131+
ifpath.endswith('.pdf'):
132+
frommatplotlibimportcheckdep_ghostscript
133+
version_tag=checkdep_ghostscript()[1].encode('utf-8')
134+
elifpath.endswith('.svg'):
135+
frommatplotlibimportcheckdep_inkscape
136+
version_tag=checkdep_inkscape().encode('utf-8')
137+
else:
138+
version_tag=None
139+
returnccache.ConversionCache._get_file_hash_static(
140+
path,block_size,version_tag)
141+
142+
123143
defconvert(filename,cache=None):
124144
"""
125145
Convert the named file into a png file. Returns the name of the

‎lib/matplotlib/testing/conversion_cache.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,32 @@ def put(self, original, converted):
115115
def_get_file_hash(self,path,block_size=2**20):
116116
ifpathinself.hash_cache:
117117
returnself.hash_cache[path]
118+
_,ext=os.path.splitext(path)
119+
version_tag=self.converter_version.get(ext)
120+
ifversion_tagisNone:
121+
warnings.warn(
122+
("Don't know the external converter for files with extension "
123+
"%s, cannot ensure cache invalidation on version update.")
124+
%ext)
125+
result=self._get_file_hash_static(path,block_size,version_tag)
126+
self.hash_cache[path]=result
127+
returnresult
128+
129+
@staticmethod
130+
def_get_file_hash_static(path,block_size,version_tag):
131+
# the parts of _get_file_hash that are called from the deprecated
132+
# compare.get_file_hash; can merge into _get_file_hash once that
133+
# function is removed
118134
md5=hashlib.md5()
119135
withopen(path,'rb')asfd:
120136
whileTrue:
121137
data=fd.read(block_size)
122138
ifnotdata:
123139
break
124140
md5.update(data)
125-
_,ext=os.path.splitext(path)
126-
version_tag=self.converter_version.get(ext)
127-
ifversion_tag:
141+
ifversion_tagisnotNone:
128142
md5.update(version_tag)
129-
else:
130-
warnings.warn(("Don't know the external converter for %s, cannot "
131-
"ensure cache invalidation on version update.")
132-
%path)
133-
134-
result=md5.hexdigest()
135-
self.hash_cache[path]=result
136-
returnresult
143+
returnmd5.hexdigest()
137144

138145
defreport(self):
139146
"""Return information about the cache.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp