8000 Merge pull request #2278 from mdboom/gs-win64c · matplotlib/matplotlib@2cded35 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2cded35

Browse files
committed
Merge pull request #2278 from mdboom/gs-win64c
Can't find 64-bit GhostScript on win64
2 parents 25a2626 + 1ddd440 commit 2cded35

File tree

3 files changed

+40
-39
lines changed

3 files changed

+40
-39
lines changed

lib/matplotlib/__init__.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,21 @@ def checkdep_dvipng():
339339
def checkdep_ghostscript():
340340
try:
341341
if sys.platform == 'win32':
342-
command_args = ['gswin32c', '--version']
342+
gs_execs = ['gswin32c', 'gswin64c', 'gs']
343343
else:
344-
command_args = ['gs', '--version']
345-
s = subprocess.Popen(command_args, stdout=subprocess.PIPE,
346-
stderr=subprocess.PIPE)
347-
v = byte2str(s.stdout.read()[:-1])
348-
return v
344+
gs_execs = ['gs']
345+
for gs_exec in gs_execs:
346+
s = subprocess.Popen(
347+
[gs_exec, '--version'], stdout=subprocess.PIPE,
348+
stderr=subprocess.PIPE)
349+
stdout, stderr = s.communicate()
350+
if s.returncode == 0:
351+
v = byte2str(stdout[:-1])
352+
return gs_exec, v
353+
354+
return None, None
349355
except (IndexError, ValueError, OSError):
350-
return None
356+
return None, None
351357

352358
def checkdep_tex():
353359
try:
@@ -412,7 +418,7 @@ def checkdep_ps_distiller(s):
412418
flag = True
413419
gs_req = '7.07'
414420
gs_sugg = '7.07'
415-
gs_v = checkdep_ghostscript()
421+
gs_exec, gs_v = checkdep_ghostscript()
416422
if compare_versions(gs_v, gs_sugg): pass
417423
elif compare_versions(gs_v, gs_req):
418424
verbose.report(('ghostscript-%s found. ghostscript-%s or later '
@@ -467,7 +473,7 @@ def checkdep_usetex(s):
467473
'backend unless dvipng-1.5 or later is '
468474
'installed on your system')
469475

470-
gs_v = checkdep_ghostscript()
476+
gs_exec, gs_v = checkdep_ghostscript()
471477
if compare_versions(gs_v, gs_sugg): pass
472478
elif compare_versions(gs_v, gs_req):
473479
verbose.report(('ghostscript-%s found. ghostscript-%s or later is '

lib/matplotlib/testing/compare.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,8 @@ def convert(old, new):
141141

142142
return convert
143143

144-
if matplotlib.checkdep_ghostscript() is not None:
145-
if sys.platform == 'win32':
146-
gs = 'gswin32c'
147-
else:
148-
gs = 'gs'
149-
144+
gs, gs_v = matplotlib.checkdep_ghostscript()
145+
if gs_v is not None:
150146
cmd = lambda old, new: \
151147
[gs, '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH',
152148
'-sOutputFile=' + new, old]

setupext.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,6 @@ def get_base_dirs():
152152
return basedir_map.get(sys.platform, ['/usr/local', '/usr'])
153153

154154

155-
def run_child_process(cmd):
156-
"""
157-
Run a subprocess as a sanity check.
158-
"""
159-
p = subprocess.Popen(cmd, shell=True,
160-
stdin=subprocess.PIPE,
161-
stdout=subprocess.PIPE,
162-
stderr=subprocess.STDOUT,
163-
close_fds=(sys.platform != 'win32'))
164-
return p.stdin, p.stdout
165-
166-
167155
def is_min_version(found, minversion):
168156
"""
169157
Returns `True` if `found` is at least as high a version as
@@ -1708,9 +1696,10 @@ class DviPng(SetupPackage):
17081696

17091697
def check(self):
17101698
try:
1711-
stdin, stdout = run_child_process('dvipng -version')
1712-
return "version %s" % stdout.readlines()[1].decode().split()[-1]
1713-
except (IndexError, ValueError):
1699+
output = check_output('dvipng -version', shell=True,
1700+
stderr=subprocess.STDOUT)
1701+
return "version %s" % output.splitlines()[1].decode().split()[-1]
1702+
except (IndexError, ValueError, subprocess.CalledProcessError):
17141703
raise CheckFailed()
17151704

17161705

@@ -1722,11 +1711,19 @@ def check(self):
17221711
try:
17231712
if sys.platform == 'win32':
17241713
command = 'gswin32c --version'
1714+
try:
1715+
output = check_output(command, shell=True,
1716+
stderr=subprocess.STDOUT)
1717+
except subprocess.CalledProcessError:
1718+
command = 'gswin64c --version'
1719+
output = check_output(command, shell=True,
1720+
stderr=subprocess.STDOUT)
17251721
else:
17261722
command = 'gs --version'
1727-
stdin, stdout = run_child_process(command)
1728-
return "version %s" % stdout.read().decode()[:-1]
1729-
except (IndexError, ValueError):
1723+
output = check_output(command, shell=True,
1724+
stderr=subprocess.STDOUT)
1725+
return "version %s" % output.decode()[:-1]
1726+
except (IndexError, ValueError, subprocess.CalledProcessError):
17301727
raise CheckFailed()
17311728

17321729

@@ -1736,12 +1733,13 @@ class LaTeX(SetupPackage):
17361733

17371734
def check(self):
17381735
try:
1739-
stdin, stdout = run_child_process('latex -version')
1740-
line = stdout.readlines()[0].decode()
1736+
output = check_output('latex -version', shell=True,
1737+
stderr=subprocess.STDOUT)
1738+
line = output.splitlines()[0].decode()
17411739
pattern = '(3\.1\d+)|(MiKTeX \d+.\d+)'
17421740
match = re.search(pattern, line)
17431741
B004 return "version %s" % match.group(0)
1744-
except (IndexError, ValueError, AttributeError):
1742+
except (IndexError, ValueError, AttributeError, subprocess.CalledProcessError):
17451743
raise CheckFailed()
17461744

17471745

@@ -1751,12 +1749,13 @@ class PdfToPs(SetupPackage):
17511749

17521750
def check(self):
17531751
try:
1754-
stdin, stdout = run_child_process('pdftops -v')
1755-
for line in stdout.readlines():
1752+
output = check_output('pdftops -v', shell=True,
1753+
stderr=subprocess.STDOUT)
1754+
for line in output.splitlines():
17561755
line = line.decode()
17571756
if 'version' in line:
17581757
return "version %s" % line.split()[2]
1759-
except (IndexError, ValueError):
1758+
except (IndexError, ValueError, subprocess.CalledProcessError):
17601759
pass
17611760

17621761
raise CheckFailed()

0 commit comments

Comments
 (0)
0