Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9d84bc

Browse files
committed
improved checks for external dependencies
svn path=/trunk/matplotlib/; revision=6471
1 parent 8858a0b commit f9d84bc

2 files changed

Lines changed: 31 additions & 23 deletions

File tree

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2008-12-02 Improve checks for external dependencies, using subprocess
2+
(instead of deprecated popen*) and distutils (for version
3+
checking) - DSD
4+
15
2008-11-30 Reimplementaion of the legend which supports baseline alignement,
26
multi-column, and expand mode. - JJL
37

lib/matplotlib/__init__.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@
9393
__revision__ = '$Revision$'
9494
__date__ = '$Date$'
9595

96-
import os, re, shutil, sys, warnings
96+
import os, re, shutil, subprocess, sys, warnings
9797
import distutils.sysconfig
98+
import distutils.version
9899

99100

100101
NEWCONFIG = False
@@ -256,58 +257,56 @@ def ge(self, level):
256257

257258
def checkdep_dvipng():
258259
try:
259-
stdin, stdout = os.popen4('dvipng -version')
260-
line = stdout.readlines()[1]
260+
s = subprocess.Popen(['dvipng','-version'], stdout=subprocess.PIPE,
261+
stderr=subprocess.PIPE)
262+
line = s.stdout.readlines()[1]
261263
v = line.split()[-1]
262-
float(v)
263264
return v
264265
except (IndexError, ValueError):
265266
return None
266267

267268
def checkdep_ghostscript():
268269
try:
269270
if sys.platform == 'win32':
270-
command = 'gswin32c --version'
271+
command_args = ['gswin32c', '--version']
271272
else:
272-
command = 'gs --version'
273-
stdin, stdout = os.popen4(command)
274-
v = stdout.read()[:-1]
275-
vtest = '.'.join(v.split('.')[:2]) # deal with version numbers like '7.07.1'
276-
float(vtest)
277-
return vtest
273+
command_args = ['gs', '--version']
274+
s = subprocess.Popen(command_args, stdout=subprocess.PIPE,
275+
stderr=subprocess.PIPE)
276+
v = s.stdout.read()[:-1]
277+
return v
278278
except (IndexError, ValueError):
279279
return None
280280

281281
def checkdep_tex():
282282
try:
283-
stdin, stdout = os.popen4('tex -version')
284-
line = stdout.readlines()[0]
283+
s = subprocess.Popen(['tex','-version'], stdout=subprocess.PIPE,
284+
stderr=subprocess.PIPE)
285+
line = s.stdout.readlines()[0]
285286
pattern = '3\.1\d+'
286287
match = re.search(pattern, line)
287288
v = match.group(0)
288-
float(v)
289289
return v
290290
except (IndexError, ValueError, AttributeError):
291291
return None
292292

293293
def checkdep_pdftops():
294294
try:
295-
stdin, stdout = os.popen4('pdftops -v')
296-
for line in stdout.readlines():
295+
s = subprocess.Popen(['pdftops','-v'], stdout=subprocess.PIPE,
296+
stderr=subprocess.PIPE)
297+
for line in s.stderr:
297298
if 'version' in line:
298299
v = line.split()[-1]
299-
float(v)
300300
return v
301301
except (IndexError, ValueError, UnboundLocalError):
302302
return None
303303

304304
def compare_versions(a, b):
305-
"return True if a is greater than b"
305+
"return True if a is greater than or equal to b"
306306
if a:
307-
a = [int(i) for i in a.split('.')]
308-
b = [int(i) for i in b.split('.')]
309-
if a[0]>b[0]: return True
310-
elif (a[0]==b[0]) and (a[1]>=b[1]): return True
307+
a = distutils.version.LooseVersion(a)
308+
b = distutils.version.LooseVersion(b)
309+
if a>=b: return True
311310
else: return False
312311
else: return False
313312

@@ -330,8 +329,13 @@ def checkdep_ps_distiller(s):
330329

331330
if s == 'xpdf':
332331
pdftops_req = '3.0'
332+
pdftops_req_alt = '0.9' # poppler version numbers, ugh
333333
pdftops_v = checkdep_pdftops()
334-
if compare_versions(pdftops_v, pdftops_req): pass
334+
if compare_versions(pdftops_v, pdftops_req):
335+
pass
336+
elif compare_versions(pdftops_v, pdftops_req_alt) and not \
337+
compare_versions(pdftops_v, '1.0'):
338+
pass
335339
else:
336340
flag = False
337341
warnings.warn(('matplotlibrc ps.usedistiller can not be set to '

0 commit comments

Comments
 (0)