Skip to content

Commit 2a85d16

Browse files
committed
Merge branch 'v1.3.x'
2 parents 79bd660 + 2cded35 commit 2a85d16

File tree

3 files changed

+41
-40
lines changed

3 files changed

+41
-40
lines changed

lib/matplotlib/__init__.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
to MATLAB®, a registered trademark of The MathWorks, Inc.
9898
9999
"""
100-
from __future__ import print_function
100+
from __future__ import print_function, absolute_import
101101

102102
import sys
103103

@@ -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
@@ -1709,9 +1697,10 @@ class DviPng(SetupPackage):
17091697

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

17171706

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

17331730

@@ -1737,12 +1734,13 @@ class LaTeX(SetupPackage):
17371734

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

17481746

@@ -1752,12 +1750,13 @@ class PdfToPs(SetupPackage):
17521750

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

17631762
raise CheckFailed()

0 commit comments

Comments
 (0)