From b9eeb44e3758e64ffc4202ef6d40d0448f2ddbc9 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Sat, 16 Jul 2016 16:02:56 -0400 Subject: [PATCH 1/2] Invalidate test cache on gs/inkscape version --- lib/matplotlib/__init__.py | 65 ++++++++++++++++++++++----------------- lib/matplotlib/testing/compare.py | 8 +++++ 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index e5e4dbbae0a..06e20820cdf 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -365,23 +365,27 @@ def checkdep_dvipng(): def checkdep_ghostscript(): - if sys.platform == 'win32': - # mgs is the name in miktex - gs_execs = ['gswin32c', 'gswin64c', 'mgs', 'gs'] - else: - gs_execs = ['gs'] - for gs_exec in gs_execs: - try: - s = subprocess.Popen( - [gs_exec, '--version'], stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - stdout, stderr = s.communicate() - if s.returncode == 0: - v = stdout[:-1].decode('ascii') - return gs_exec, v - except (IndexError, ValueError, OSError): - pass - return None, None + if checkdep_ghostscript.executable is None: + if sys.platform == 'win32': + # mgs is the name in miktex + gs_execs = ['gswin32c', 'gswin64c', 'mgs', 'gs'] + else: + gs_execs = ['gs'] + for gs_exec in gs_execs: + try: + s = subprocess.Popen( + [gs_exec, '--version'], stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = s.communicate() + if s.returncode == 0: + v = stdout[:-1].decode('ascii') + checkdep_ghostscript.executable = gs_exec + checkdep_ghostscript.version = v + except (IndexError, ValueError, OSError): + pass + return checkdep_ghostscript.executable, checkdep_ghostscript.version +checkdep_ghostscript.executable = None +checkdep_ghostscript.version = None def checkdep_tex(): @@ -413,18 +417,21 @@ def checkdep_pdftops(): def checkdep_inkscape(): - try: - s = subprocess.Popen(['inkscape', '-V'], stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - stdout, stderr = s.communicate() - lines = stdout.decode('ascii').split('\n') - for line in lines: - if 'Inkscape' in line: - v = line.split()[1] - break - return v - except (IndexError, ValueError, UnboundLocalError, OSError): - return None + if checkdep_inkscape.version is None: + try: + s = subprocess.Popen(['inkscape', '-V'], stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = s.communicate() + lines = stdout.decode('ascii').split('\n') + for line in lines: + if 'Inkscape' in line: + v = line.split()[1] + break + checkdep_inkscape.version = v + except (IndexError, ValueError, UnboundLocalError, OSError): + pass + return checkdep_inkscape.version +checkdep_inkscape.version = None def checkdep_xmllint(): diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index d0b89e20429..910d212bef2 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -99,6 +99,14 @@ def get_file_hash(path, block_size=2 ** 20): if not data: break md5.update(data) + + if path.endswith('.pdf'): + from matplotlib import checkdep_ghostscript + md5.update(checkdep_ghostscript()[1]) + elif path.endswith('.svg'): + from matplotlib import checkdep_inkscape + md5.update(checkdep_inkscape()) + return md5.hexdigest() From b9407756ccb4c2ee86d42df852e70141f3649cb3 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Sat, 16 Jul 2016 16:54:52 -0400 Subject: [PATCH 2/2] Python 3 fix --- lib/matplotlib/testing/compare.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index 910d212bef2..08f7c78c74d 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -102,10 +102,10 @@ def get_file_hash(path, block_size=2 ** 20): if path.endswith('.pdf'): from matplotlib import checkdep_ghostscript - md5.update(checkdep_ghostscript()[1]) + md5.update(checkdep_ghostscript()[1].encode('utf-8')) elif path.endswith('.svg'): from matplotlib import checkdep_inkscape - md5.update(checkdep_inkscape()) + md5.update(checkdep_inkscape().encode('utf-8')) return md5.hexdigest()