Skip to content

Commit 05b5fb5

Browse files
committed
Reinstate deleted functions
With a deprecation decorator
1 parent 8d90a48 commit 05b5fb5

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
import matplotlib
1313
from matplotlib import cbook
1414
from matplotlib.compat import subprocess
15+
from matplotlib.testing import conversion_cache as ccache
1516
from matplotlib.testing.exceptions import ImageComparisonFailure
1617
from matplotlib import _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+
def get_cache_dir():
126+
return ccache.ConversionCache.get_cache_dir()
127+
128+
129+
@cbook.deprecated('2.1', addendum='Use ConversionCache instead')
130+
def get_file_hash(path, block_size=2 ** 20):
131+
if path.endswith('.pdf'):
132+
from matplotlib import checkdep_ghostscript
133+
version_tag = checkdep_ghostscript()[1].encode('utf-8')
134+
elif path.endswith('.svg'):
135+
from matplotlib import checkdep_inkscape
136+
version_tag = checkdep_inkscape().encode('utf-8')
137+
else:
138+
version_tag = None
139+
return ccache.ConversionCache._get_file_hash_static(
140+
path, block_size, version_tag)
141+
142+
123143
def convert(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
if path in self.hash_cache:
117117
return self.hash_cache[path]
118+
_, ext = os.path.splitext(path)
119+
version_tag = self.converter_version.get(ext)
120+
if version_tag is None:
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+
return result
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
with open(path, 'rb') as fd:
120136
while True:
121137
data = fd.read(block_size)
122138
if not data:
123139
break
124140
md5.update(data)
125-
_, ext = os.path.splitext(path)
126-
version_tag = self.converter_version.get(ext)
127-
if version_tag:
141+
if version_tag is not None:
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-
return result
143+
return md5.hexdigest()
137144

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

0 commit comments

Comments
 (0)