diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index b787b5a9a057..25d7e04f3103 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -343,8 +343,9 @@ def checkdep_dvipng(): try: s = subprocess.Popen(['dvipng','-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - line = s.stdout.readlines()[1] - v = line.split()[-1].decode('ascii') + stdout, stderr = s.communicate() + line = stdout.decode('ascii').split('\n')[1] + v = line.split()[-1] return v except (IndexError, ValueError, OSError): return None @@ -371,7 +372,8 @@ def checkdep_tex(): try: s = subprocess.Popen(['tex','-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - line = s.stdout.readlines()[0].decode('ascii') + stdout, stderr = s.communicate() + line = stdout.decode('ascii').split('\n')[0] pattern = '3\.1\d+' match = re.search(pattern, line) v = match.group(0) @@ -383,9 +385,11 @@ def checkdep_pdftops(): try: s = subprocess.Popen(['pdftops','-v'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - for line in s.stderr: - if b'version' in line: - v = line.split()[-1].decode('ascii') + stdout, stderr = s.communicate() + lines = stderr.decode('ascii').split('\n') + for line in lines: + if 'version' in line: + v = line.split()[-1] return v except (IndexError, ValueError, UnboundLocalError, OSError): return None @@ -394,9 +398,11 @@ def checkdep_inkscape(): try: s = subprocess.Popen(['inkscape','-V'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - for line in s.stdout: - if b'Inkscape' in line: - v = line.split()[1].decode('ascii') + stdout, stderr = s.communicate() + lines = stdout.decode('ascii').split('\n') + for line in lines: + if 'Inkscape' in line: + v = line.split()[1] break return v except (IndexError, ValueError, UnboundLocalError, OSError): @@ -406,9 +412,11 @@ def checkdep_xmllint(): try: s = subprocess.Popen(['xmllint','--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - for line in s.stderr: - if b'version' in line: - v = line.split()[-1].decode('ascii') + stdout, stderr = s.communicate() + lines = stderr.decode('ascii').split('\n') + for line in lines: + if 'version' in line: + v = line.split()[-1] break return v except (IndexError, ValueError, UnboundLocalError, OSError): diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 066cb00e1092..eaebf15bf4ae 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -90,12 +90,13 @@ def gs_version(self): pass from matplotlib.compat.subprocess import Popen, PIPE - pipe = Popen(self.gs_exe + " --version", - shell=True, stdout=PIPE).stdout + s = Popen(self.gs_exe + " --version", + shell=True, stdout=PIPE) + pipe, stderr = s.communicate() if six.PY3: - ver = pipe.read().decode('ascii') + ver = pipe.decode('ascii') else: - ver = pipe.read() + ver = pipe gs_version = tuple(map(int, ver.strip().split("."))) self._cached["gs_version"] = gs_version diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index 1b6aac6e37e5..93aca46e28c1 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -40,6 +40,8 @@ def _test_savefig_to_stringio(format='ps'): assert values[0] == values[1] assert values[1] == values[2].replace(b'\r\n', b'\n') + for buffer in buffers: + buffer.close() @cleanup diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index 51758fe6851e..8ff931a0d410 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -70,16 +70,16 @@ def dvipng_hack_alpha(): try: p = Popen(['dvipng', '-version'], stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=(sys.platform != 'win32')) + stdout, stderr = p.communicate() except OSError: mpl.verbose.report('No dvipng was found', 'helpful') return False - stdin, stdout = p.stdin, p.stdout - for line in stdout: - if line.startswith(b'dvipng '): + lines = stdout.decode('ascii').split('\n') + for line in lines: + if line.startswith('dvipng '): version = line.split()[-1] mpl.verbose.report('Found dvipng version %s' % version, 'helpful') - version = version.decode('ascii') version = distutils.version.LooseVersion(version) return version < distutils.version.LooseVersion('1.6') mpl.verbose.report('Unexpected response from dvipng -version', 'helpful')