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

Skip to content

Commit bd67783

Browse files
committed
Rewrite checks to use communicate.
This ensures that file handles are cloesed
1 parent 4314d44 commit bd67783

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lib/matplotlib/__init__.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,9 @@ def checkdep_dvipng():
343343
try:
344344
s = subprocess.Popen(['dvipng','-version'], stdout=subprocess.PIPE,
345345
stderr=subprocess.PIPE)
346-
line = s.stdout.readlines()[1]
347-
v = line.split()[-1].decode('ascii')
346+
stdout, stderr = s.communicate()
347+
line = stdout.decode('ascii').split('\n')[1]
348+
v = line.split()[-1]
348349
return v
349350
except (IndexError, ValueError, OSError):
350351
return None
@@ -371,7 +372,8 @@ def checkdep_tex():
371372
try:
372373
s = subprocess.Popen(['tex','-version'], stdout=subprocess.PIPE,
373374
stderr=subprocess.PIPE)
374-
line = s.stdout.readlines()[0].decode('ascii')
375+
stdout, stderr = s.communicate()
376+
line = stdout.decode('ascii').split('\n')[0]
375377
pattern = '3\.1\d+'
376378
match = re.search(pattern, line)
377379
v = match.group(0)
@@ -383,9 +385,10 @@ def checkdep_pdftops():
383385
try:
384386
s = subprocess.Popen(['pdftops','-v'], stdout=subprocess.PIPE,
385387
stderr=subprocess.PIPE)
386-
for line in s.stderr:
387-
if b'version' in line:
388-
v = line.split()[-1].decode('ascii')
388+
stdout, stderr = s.communicate()
389+
if b'version' in stderr:
390+
line = stderr.decode('ascii').split('\n')[0]
391+
v = line.split()[-1]
389392
return v
390393
except (IndexError, ValueError, UnboundLocalError, OSError):
391394
return None
@@ -394,10 +397,9 @@ def checkdep_inkscape():
394397
try:
395398
s = subprocess.Popen(['inkscape','-V'], stdout=subprocess.PIPE,
396399
stderr=subprocess.PIPE)
397-
for line in s.stdout:
398-
if b'Inkscape' in line:
399-
v = line.split()[1].decode('ascii')
400-
break
400+
stdout, stderr = s.communicate()
401+
if b'Inkscape' in stdout:
402+
v = stdout.split()[1].decode('ascii')
401403
return v
402404
except (IndexError, ValueError, UnboundLocalError, OSError):
403405
return None
@@ -406,10 +408,10 @@ def checkdep_xmllint():
406408
try:
407409
s = subprocess.Popen(['xmllint','--version'], stdout=subprocess.PIPE,
408410
stderr=subprocess.PIPE)
409-
for line in s.stderr:
410-
if b'version' in line:
411-
v = line.split()[-1].decode('ascii')
412-
break
411+
stdout, stderr = s.communicate()
412+
if b'version' in stderr:
413+
line = stderr.decode('ascii').split('\n')[0]
414+
v = line.split()[-1]
413415
return v
414416
except (IndexError, ValueError, UnboundLocalError, OSError):
415417
return None

0 commit comments

Comments
 (0)