diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 9d8cd5eca5c5..384350884916 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -324,15 +324,21 @@ def checkdep_dvipng(): def checkdep_ghostscript(): try: if sys.platform == 'win32': - command_args = ['gswin32c', '--version'] + gs_execs = ['gswin32c', 'gswin64c', 'gs'] else: - command_args = ['gs', '--version'] - s = subprocess.Popen(command_args, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - v = byte2str(s.stdout.read()[:-1]) - return v + gs_execs = ['gs'] + for gs_exec in gs_execs: + s = subprocess.Popen( + [gs_exec, '--version'], stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = s.communicate() + if s.returncode == 0: + v = byte2str(stdout[:-1]) + return gs_exec, v + + return None, None except (IndexError, ValueError, OSError): - return None + return None, None def checkdep_tex(): try: @@ -397,7 +403,7 @@ def checkdep_ps_distiller(s): flag = True gs_req = '7.07' gs_sugg = '7.07' - gs_v = checkdep_ghostscript() + gs_exec, gs_v = checkdep_ghostscript() if compare_versions(gs_v, gs_sugg): pass elif compare_versions(gs_v, gs_req): verbose.report(('ghostscript-%s found. ghostscript-%s or later ' @@ -452,7 +458,7 @@ def checkdep_usetex(s): 'backend unless dvipng-1.5 or later is ' 'installed on your system') - gs_v = checkdep_ghostscript() + gs_exec, gs_v = checkdep_ghostscript() if compare_versions(gs_v, gs_sugg): pass elif compare_versions(gs_v, gs_req): verbose.report(('ghostscript-%s found. ghostscript-%s or later is ' diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index 9812e123aab1..de89d2130800 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -141,12 +141,8 @@ def convert(old, new): return convert -if matplotlib.checkdep_ghostscript() is not None: - if sys.platform == 'win32': - gs = 'gswin32c' - else: - gs = 'gs' - +gs, gs_v = matplotlib.checkdep_ghostscript() +if gs_v is not None: cmd = lambda old, new: \ [gs, '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH', '-sOutputFile=' + new, old] diff --git a/setupext.py b/setupext.py index 17e1ef1fa602..8c1ce45e91b8 100644 --- a/setupext.py +++ b/setupext.py @@ -152,18 +152,6 @@ def get_base_dirs(): return basedir_map.get(sys.platform, ['/usr/local', '/usr']) -def run_child_process(cmd): - """ - Run a subprocess as a sanity check. - """ - p = subprocess.Popen(cmd, shell=True, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - close_fds=(sys.platform != 'win32')) - return p.stdin, p.stdout - - def is_min_version(found, minversion): """ Returns `True` if `found` is at least as high a version as @@ -1713,9 +1701,10 @@ class DviPng(SetupPackage): def check(self): try: - stdin, stdout = run_child_process('dvipng -version') - return "version %s" % stdout.readlines()[1].decode().split()[-1] - except (IndexError, ValueError): + output = check_output('dvipng -version', shell=True, + stderr=subprocess.STDOUT) + return "version %s" % output.splitlines()[1].decode().split()[-1] + except (IndexError, ValueError, subprocess.CalledProcessError): raise CheckFailed() @@ -1727,11 +1716,19 @@ def check(self): try: if sys.platform == 'win32': command = 'gswin32c --version' + try: + output = check_output(command, shell=True, + stderr=subprocess.STDOUT) + except subprocess.CalledProcessError: + command = 'gswin64c --version' + output = check_output(command, shell=True, + stderr=subprocess.STDOUT) else: command = 'gs --version' - stdin, stdout = run_child_process(command) - return "version %s" % stdout.read().decode()[:-1] - except (IndexError, ValueError): + output = check_output(command, shell=True, + stderr=subprocess.STDOUT) + return "version %s" % output.decode()[:-1] + except (IndexError, ValueError, subprocess.CalledProcessError): raise CheckFailed() @@ -1741,12 +1738,13 @@ class LaTeX(SetupPackage): def check(self): try: - stdin, stdout = run_child_process('latex -version') - line = stdout.readlines()[0].decode() + output = check_output('latex -version', shell=True, + stderr=subprocess.STDOUT) + line = output.splitlines()[0].decode() pattern = '(3\.1\d+)|(MiKTeX \d+.\d+)' match = re.search(pattern, line) return "version %s" % match.group(0) - except (IndexError, ValueError, AttributeError): + except (IndexError, ValueError, AttributeError, subprocess.CalledProcessError): raise CheckFailed() @@ -1756,12 +1754,13 @@ class PdfToPs(SetupPackage): def check(self): try: - stdin, stdout = run_child_process('pdftops -v') - for line in stdout.readlines(): + output = check_output('pdftops -v', shell=True, + stderr=subprocess.STDOUT) + for line in output.splitlines(): line = line.decode() if 'version' in line: return "version %s" % line.split()[2] - except (IndexError, ValueError): + except (IndexError, ValueError, subprocess.CalledProcessError): pass raise CheckFailed()