From 0755aa60152eae6c9ec2bbd2886084247f41b68c Mon Sep 17 00:00:00 2001 From: Matt Giuca Date: Tue, 12 Mar 2013 18:16:34 +1100 Subject: [PATCH 1/8] Added new module, matplotlib.subprocess_fixed, as a replacement for subprocess. cbook: Moved check_output to subprocess_fixed. backend_pgf: Import check_output from subprocess_fixed instead of cbook. --- lib/matplotlib/backends/backend_pgf.py | 2 +- lib/matplotlib/cbook.py | 43 ----------------- lib/matplotlib/subprocess_fixed.py | 64 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 44 deletions(-) create mode 100644 lib/matplotlib/subprocess_fixed.py diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index 82c3718c7dad..f2776d4ac2a0 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -21,7 +21,7 @@ from matplotlib import font_manager from matplotlib.ft2font import FT2Font from matplotlib.cbook import is_string_like, is_writable_file_like -from matplotlib.cbook import check_output +from matplotlib.subprocess_fixed import check_output ############################################################################### diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index 0616782d79a6..04b4724fc48d 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -17,7 +17,6 @@ import locale import os import re -import subprocess import sys import threading import time @@ -1795,45 +1794,3 @@ def get_instancemethod(self): else: def _putmask(a, mask, values): return np.copyto(a, values, where=mask) - - -def _check_output(*popenargs, **kwargs): - r"""Run command with arguments and return its output as a byte - string. - - If the exit code was non-zero it raises a CalledProcessError. The - CalledProcessError object will have the return code in the - returncode - attribute and output in the output attribute. - - The arguments are the same as for the Popen constructor. Example:: - - >>> check_output(["ls", "-l", "/dev/null"]) - 'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n' - - The stdout argument is not allowed as it is used internally. - To capture standard error in the result, use stderr=STDOUT.:: - - >>> check_output(["/bin/sh", "-c", - ... "ls -l non_existent_file ; exit 0"], - ... stderr=STDOUT) - 'ls: non_existent_file: No such file or directory\n' - """ - if 'stdout' in kwargs: - raise ValueError('stdout argument not allowed, it will be overridden.') - process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs) - output, unused_err = process.communicate() - retcode = process.poll() - if retcode: - cmd = kwargs.get("args") - if cmd is None: - cmd = popenargs[0] - raise subprocess.CalledProcessError(retcode, cmd, output=output) - return output - - -# python2.7's subprocess provides a check_output method -if hasattr(subprocess, 'check_output'): - check_output = subprocess.check_output -else: - check_output = _check_output diff --git a/lib/matplotlib/subprocess_fixed.py b/lib/matplotlib/subprocess_fixed.py new file mode 100644 index 000000000000..d2e6cd70c06c --- /dev/null +++ b/lib/matplotlib/subprocess_fixed.py @@ -0,0 +1,64 @@ +""" +A replacement wrapper around the subprocess module, with a number of +work-arounds: +- Provides the check_output function (which subprocess only provides from Python + 2.7 onwards). + +Instead of importing subprocess, other modules should use this as follows: + +import subprocess_fixed as subprocess + +This module is safe to import from anywhere within matplotlib. +""" + +from __future__ import print_function + +import subprocess + +__all__ = ['Popen', 'PIPE', 'STDOUT', 'check_output'] + +Popen = subprocess.Popen +PIPE = subprocess.PIPE +STDOUT = subprocess.STDOUT + + +def _check_output(*popenargs, **kwargs): + r"""Run command with arguments and return its output as a byte + string. + + If the exit code was non-zero it raises a CalledProcessError. The + CalledProcessError object will have the return code in the + returncode + attribute and output in the output attribute. + + The arguments are the same as for the Popen constructor. Example:: + + >>> check_output(["ls", "-l", "/dev/null"]) + 'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n' + + The stdout argument is not allowed as it is used internally. + To capture standard error in the result, use stderr=STDOUT.:: + + >>> check_output(["/bin/sh", "-c", + ... "ls -l non_existent_file ; exit 0"], + ... stderr=STDOUT) + 'ls: non_existent_file: No such file or directory\n' + """ + if 'stdout' in kwargs: + raise ValueError('stdout argument not allowed, it will be overridden.') + process = Popen(stdout=PIPE, *popenargs, **kwargs) + output, unused_err = process.communicate() + retcode = process.poll() + if retcode: + cmd = kwargs.get("args") + if cmd is None: + cmd = popenargs[0] + raise subprocess.CalledProcessError(retcode, cmd, output=output) + return output + + +# python2.7's subprocess provides a check_output method +if hasattr(subprocess, 'check_output'): + check_output = subprocess.check_output +else: + check_output = _check_output From 52c075f3a6071a2a8ba25f7d3ac1b21f747ddefb Mon Sep 17 00:00:00 2001 From: Matt Giuca Date: Tue, 12 Mar 2013 18:17:47 +1100 Subject: [PATCH 2/8] All modules now use matplotlib.subprocess_fixed instead of subprocess. --- lib/matplotlib/__init__.py | 3 ++- lib/matplotlib/animation.py | 2 +- lib/matplotlib/backends/backend_pgf.py | 2 +- lib/matplotlib/backends/backend_ps.py | 2 +- lib/matplotlib/cbook.py | 2 +- lib/matplotlib/dviread.py | 2 +- lib/matplotlib/font_manager.py | 3 ++- lib/matplotlib/testing/compare.py | 2 +- lib/matplotlib/testing/util.py | 2 +- lib/matplotlib/tests/test_backend_pgf.py | 2 +- lib/matplotlib/texmanager.py | 2 +- 11 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index a867d4e4a34f..bbc8d7de7748 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -124,7 +124,7 @@ '.'.join(str(x) for x in _required), sys.version_info[0])) -import os, re, shutil, subprocess, warnings +import os, re, shutil, warnings import distutils.sysconfig import distutils.version @@ -132,6 +132,7 @@ # definitions, so it is safe to import from it here. from matplotlib.cbook import MatplotlibDeprecationWarning from matplotlib.cbook import is_string_like +import matplotlib.subprocess_fixed as subprocess try: reload diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index acb8e51e6753..1a70cb458cf5 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -20,8 +20,8 @@ import sys import itertools import contextlib -import subprocess from matplotlib.cbook import iterable, is_string_like +import matplotlib.subprocess_fixed as subprocess from matplotlib import verbose from matplotlib import rcParams diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index f2776d4ac2a0..36e5bcccc208 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -7,7 +7,6 @@ import shutil import tempfile import codecs -import subprocess import atexit import weakref @@ -21,6 +20,7 @@ from matplotlib import font_manager from matplotlib.ft2font import FT2Font from matplotlib.cbook import is_string_like, is_writable_file_like +import matplotlib.subprocess_fixed as subprocess from matplotlib.subprocess_fixed import check_output diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index aa02e8959d68..1e685f162b21 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -88,7 +88,7 @@ def gs_version(self): except KeyError: pass - from subprocess import Popen, PIPE + from matplotlib.subprocess_fixed import Popen, PIPE pipe = Popen(self.gs_exe + " --version", shell=True, stdout=PIPE).stdout if sys.version_info[0] >= 3: diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index 04b4724fc48d..bc84ddf81652 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -1211,7 +1211,7 @@ def restrict_dict(d, keys): def report_memory(i=0): # argument may go away 'return the memory consumed by process' - from subprocess import Popen, PIPE + from matplotlib.subprocess_fixed import Popen, PIPE pid = os.getpid() if sys.platform == 'sunos5': a2 = Popen('ps -p %d -o osz' % pid, shell=True, diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index 6bc3793ee3f1..91b28a247dcf 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -23,9 +23,9 @@ import errno import matplotlib import matplotlib.cbook as mpl_cbook +import matplotlib.subprocess_fixed as subprocess import numpy as np import struct -import subprocess import sys if sys.version_info[0] >= 3: diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index 373601875d22..99b9b269fcee 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -43,7 +43,7 @@ see license/LICENSE_TTFQUERY. """ -import os, sys, subprocess, warnings +import os, sys, warnings try: set except NameError: @@ -56,6 +56,7 @@ import matplotlib.cbook as cbook from matplotlib.fontconfig_pattern import \ parse_fontconfig_pattern, generate_fontconfig_pattern +import matplotlib.subprocess_fixed as subprocess try: import cPickle as pickle diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index 62a254b34aef..09372340e46b 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -7,6 +7,7 @@ from __future__ import division import matplotlib +import matplotlib.subprocess_fixed as subprocess from matplotlib.testing.noseclasses import ImageComparisonFailure from matplotlib.testing import image_util, util from matplotlib import _png @@ -17,7 +18,6 @@ import os import numpy as np import shutil -import subprocess import sys from functools import reduce diff --git a/lib/matplotlib/testing/util.py b/lib/matplotlib/testing/util.py index a436969255aa..857172d0e913 100644 --- a/lib/matplotlib/testing/util.py +++ b/lib/matplotlib/testing/util.py @@ -1,5 +1,5 @@ -import subprocess import sys +import matplotlib.subprocess_fixed as subprocess class MiniExpect: diff --git a/lib/matplotlib/tests/test_backend_pgf.py b/lib/matplotlib/tests/test_backend_pgf.py index 98b3f1aa6721..f754e947d5c8 100644 --- a/lib/matplotlib/tests/test_backend_pgf.py +++ b/lib/matplotlib/tests/test_backend_pgf.py @@ -2,12 +2,12 @@ import os import shutil -import subprocess import numpy as np import nose from nose.plugins.skip import SkipTest import matplotlib as mpl import matplotlib.pyplot as plt +import matplotlib.subprocess_fixed as subprocess from matplotlib.testing.compare import compare_images, ImageComparisonFailure from matplotlib.testing.decorators import _image_directories diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index 3023d8fec5bb..db49b675db14 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -41,7 +41,6 @@ import os import shutil import sys -from subprocess import Popen, PIPE, STDOUT from hashlib import md5 @@ -52,6 +51,7 @@ from matplotlib._png import read_png from matplotlib.cbook import mkdirs import matplotlib.dviread as dviread +from matplotlib.subprocess_fixed import Popen, PIPE, STDOUT import re DEBUG = False From b29c93c1c5cf04b4691345cad26b896ab0e719c3 Mon Sep 17 00:00:00 2001 From: Matt Giuca Date: Tue, 12 Mar 2013 18:22:29 +1100 Subject: [PATCH 3/8] subprocess_fixed: Gracefully handle platforms without subprocess.Popen. If subprocess.Popen is missing (for example, on Google App Engine), replaces it with a dummy version that raises OSError. In these environments, calls to subprocess will be handled properly as if the called app could not be found, instead of raising AttributeError. --- lib/matplotlib/subprocess_fixed.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/subprocess_fixed.py b/lib/matplotlib/subprocess_fixed.py index d2e6cd70c06c..f37dd52be048 100644 --- a/lib/matplotlib/subprocess_fixed.py +++ b/lib/matplotlib/subprocess_fixed.py @@ -3,6 +3,8 @@ work-arounds: - Provides the check_output function (which subprocess only provides from Python 2.7 onwards). +- Provides a stub implementation of subprocess members on Google App Engine + (which are missing in subprocess). Instead of importing subprocess, other modules should use this as follows: @@ -17,9 +19,19 @@ __all__ = ['Popen', 'PIPE', 'STDOUT', 'check_output'] -Popen = subprocess.Popen -PIPE = subprocess.PIPE -STDOUT = subprocess.STDOUT + +if hasattr(subprocess, 'Popen'): + Popen = subprocess.Popen + # Assume that it also has the other constants. + PIPE = subprocess.PIPE + STDOUT = subprocess.STDOUT +else: + # In restricted environments (such as Google App Engine), these are + # non-existent. Replace them with dummy versions that always raise OSError. + def Popen(*args, **kwargs): + raise OSError("subprocess.Popen is not supported") + PIPE = -1 + STDOUT = -2 def _check_output(*popenargs, **kwargs): From a117e19895097a442c24702b7a3f43be9d90c056 Mon Sep 17 00:00:00 2001 From: Matt Giuca Date: Tue, 12 Mar 2013 18:26:31 +1100 Subject: [PATCH 4/8] texmanager: Ignore dvipng if it cannot be found, instead of raising OSError. --- lib/matplotlib/texmanager.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index db49b675db14..b6d3f3b2a9cc 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -63,8 +63,12 @@ def dvipng_hack_alpha(): - p = Popen('dvipng -version', shell=True, stdin=PIPE, stdout=PIPE, - stderr=STDOUT, close_fds=(sys.platform != 'win32')) + try: + p = Popen('dvipng -version', stdin=PIPE, stdout=PIPE, stderr=STDOUT, + close_fds=(sys.platform != 'win32')) + 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 '): @@ -74,7 +78,7 @@ def dvipng_hack_alpha(): version = version.decode('ascii') version = distutils.version.LooseVersion(version) return version < distutils.version.LooseVersion('1.6') - mpl.verbose.report('No dvipng was found', 'helpful') + mpl.verbose.report('Unexpected response from dvipng -version', 'helpful') return False From ea342b6bc123addaa42c854d3a688b0b3a8bc664 Mon Sep 17 00:00:00 2001 From: Matt Giuca Date: Tue, 12 Mar 2013 18:31:05 +1100 Subject: [PATCH 5/8] cbook.report_memory: If ps not found, raises NotImplementedError, not OSError. --- lib/matplotlib/cbook.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index bc84ddf81652..90ec6ab6666b 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -1214,16 +1214,31 @@ def report_memory(i=0): # argument may go away from matplotlib.subprocess_fixed import Popen, PIPE pid = os.getpid() if sys.platform == 'sunos5': - a2 = Popen('ps -p %d -o osz' % pid, shell=True, - stdout=PIPE).stdout.readlines() + try: + a2 = Popen('ps -p %d -o osz' % pid, shell=True, + stdout=PIPE).stdout.readlines() + except OSError: + raise NotImplementedError( + "report_memory works on Sun OS only if " + "the 'ps' program is found") mem = int(a2[-1].strip()) elif sys.platform.startswith('linux'): - a2 = Popen('ps -p %d -o rss,sz' % pid, shell=True, - stdout=PIPE).stdout.readlines() + try: + a2 = Popen('ps -p %d -o rss,sz' % pid, shell=True, + stdout=PIPE).stdout.readlines() + except OSError: + raise NotImplementedError( + "report_memory works on Linux only if " + "the 'ps' program is found") mem = int(a2[1].split()[1]) elif sys.platform.startswith('darwin'): - a2 = Popen('ps -p %d -o rss,vsz' % pid, shell=True, - stdout=PIPE).stdout.readlines() + try: + a2 = Popen('ps -p %d -o rss,vsz' % pid, shell=True, + stdout=PIPE).stdout.readlines() + except OSError: + raise NotImplementedError( + "report_memory works on Mac OS only if " + "the 'ps' program is found") mem = int(a2[1].split()[0]) elif sys.platform.startswith('win'): try: From f41000d6f5ca2dc15e2c99da29b501185260d241 Mon Sep 17 00:00:00 2001 From: Matt Giuca Date: Mon, 18 Mar 2013 16:44:39 +1100 Subject: [PATCH 6/8] Moved matplotlib.subprocess_fixed to matplotlib.compat.subprocess. --- lib/matplotlib/__init__.py | 2 +- lib/matplotlib/animation.py | 2 +- lib/matplotlib/backends/backend_pgf.py | 4 ++-- lib/matplotlib/backends/backend_ps.py | 2 +- lib/matplotlib/cbook.py | 2 +- lib/matplotlib/compat/__init__.py | 0 lib/matplotlib/{subprocess_fixed.py => compat/subprocess.py} | 2 +- lib/matplotlib/dviread.py | 2 +- lib/matplotlib/font_manager.py | 2 +- lib/matplotlib/testing/compare.py | 2 +- lib/matplotlib/testing/util.py | 2 +- lib/matplotlib/tests/test_backend_pgf.py | 2 +- lib/matplotlib/texmanager.py | 2 +- setupext.py | 1 + 14 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 lib/matplotlib/compat/__init__.py rename lib/matplotlib/{subprocess_fixed.py => compat/subprocess.py} (98%) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index bbc8d7de7748..997e86f40c93 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -132,7 +132,7 @@ # definitions, so it is safe to import from it here. from matplotlib.cbook import MatplotlibDeprecationWarning from matplotlib.cbook import is_string_like -import matplotlib.subprocess_fixed as subprocess +from matplotlib.compat import subprocess try: reload diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 1a70cb458cf5..de2d17a30eae 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -21,7 +21,7 @@ import itertools import contextlib from matplotlib.cbook import iterable, is_string_like -import matplotlib.subprocess_fixed as subprocess +from matplotlib.compat import subprocess from matplotlib import verbose from matplotlib import rcParams diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index 36e5bcccc208..940f5a00861e 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -20,8 +20,8 @@ from matplotlib import font_manager from matplotlib.ft2font import FT2Font from matplotlib.cbook import is_string_like, is_writable_file_like -import matplotlib.subprocess_fixed as subprocess -from matplotlib.subprocess_fixed import check_output +from matplotlib.compat import subprocess +from matplotlib.compat.subprocess import check_output ############################################################################### diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 1e685f162b21..dab86b29f2d2 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -88,7 +88,7 @@ def gs_version(self): except KeyError: pass - from matplotlib.subprocess_fixed import Popen, PIPE + from matplotlib.compat.subprocess import Popen, PIPE pipe = Popen(self.gs_exe + " --version", shell=True, stdout=PIPE).stdout if sys.version_info[0] >= 3: diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index 90ec6ab6666b..da44e47f2085 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -1211,7 +1211,7 @@ def restrict_dict(d, keys): def report_memory(i=0): # argument may go away 'return the memory consumed by process' - from matplotlib.subprocess_fixed import Popen, PIPE + from matplotlib.compat.subprocess import Popen, PIPE pid = os.getpid() if sys.platform == 'sunos5': try: diff --git a/lib/matplotlib/compat/__init__.py b/lib/matplotlib/compat/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/matplotlib/subprocess_fixed.py b/lib/matplotlib/compat/subprocess.py similarity index 98% rename from lib/matplotlib/subprocess_fixed.py rename to lib/matplotlib/compat/subprocess.py index f37dd52be048..62cff86d869f 100644 --- a/lib/matplotlib/subprocess_fixed.py +++ b/lib/matplotlib/compat/subprocess.py @@ -8,7 +8,7 @@ Instead of importing subprocess, other modules should use this as follows: -import subprocess_fixed as subprocess +from matplotlib.compat import subprocess This module is safe to import from anywhere within matplotlib. """ diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index 91b28a247dcf..a918154a5884 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -23,7 +23,7 @@ import errno import matplotlib import matplotlib.cbook as mpl_cbook -import matplotlib.subprocess_fixed as subprocess +from matplotlib.compat import subprocess import numpy as np import struct import sys diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index 99b9b269fcee..28ac73453e26 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -54,9 +54,9 @@ from matplotlib import rcParams, get_configdir from matplotlib.cbook import is_string_like import matplotlib.cbook as cbook +from matplotlib.compat import subprocess from matplotlib.fontconfig_pattern import \ parse_fontconfig_pattern, generate_fontconfig_pattern -import matplotlib.subprocess_fixed as subprocess try: import cPickle as pickle diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index 09372340e46b..17d247746bf7 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -7,7 +7,7 @@ from __future__ import division import matplotlib -import matplotlib.subprocess_fixed as subprocess +from matplotlib.compat import subprocess from matplotlib.testing.noseclasses import ImageComparisonFailure from matplotlib.testing import image_util, util from matplotlib import _png diff --git a/lib/matplotlib/testing/util.py b/lib/matplotlib/testing/util.py index 857172d0e913..4a0fa43e8b18 100644 --- a/lib/matplotlib/testing/util.py +++ b/lib/matplotlib/testing/util.py @@ -1,5 +1,5 @@ import sys -import matplotlib.subprocess_fixed as subprocess +from matplotlib.compat import subprocess class MiniExpect: diff --git a/lib/matplotlib/tests/test_backend_pgf.py b/lib/matplotlib/tests/test_backend_pgf.py index f754e947d5c8..2e702fa16380 100644 --- a/lib/matplotlib/tests/test_backend_pgf.py +++ b/lib/matplotlib/tests/test_backend_pgf.py @@ -7,7 +7,7 @@ from nose.plugins.skip import SkipTest import matplotlib as mpl import matplotlib.pyplot as plt -import matplotlib.subprocess_fixed as subprocess +from matplotlib.compat import subprocess from matplotlib.testing.compare import compare_images, ImageComparisonFailure from matplotlib.testing.decorators import _image_directories diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index b6d3f3b2a9cc..da666b1a138e 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -50,8 +50,8 @@ from matplotlib import rcParams from matplotlib._png import read_png from matplotlib.cbook import mkdirs +from matplotlib.compat.subprocess import Popen, PIPE, STDOUT import matplotlib.dviread as dviread -from matplotlib.subprocess_fixed import Popen, PIPE, STDOUT import re DEBUG = False diff --git a/setupext.py b/setupext.py index 3f374b4d4e46..85ff433559fd 100644 --- a/setupext.py +++ b/setupext.py @@ -494,6 +494,7 @@ def get_packages(self): 'matplotlib', 'matplotlib.backends', 'matplotlib.backends.qt4_editor', + 'matplotlib.compat', 'matplotlib.projections', 'matplotlib.sphinxext', 'matplotlib.testing', From 888fa204164a30f0940e17503663ebebb2a4afb9 Mon Sep 17 00:00:00 2001 From: Matt Giuca Date: Tue, 19 Mar 2013 10:00:16 +1100 Subject: [PATCH 7/8] api_changes: Document the API changes. - The subtle change to cbook.report_memory's exception types. - Moving subprocess_fixed to compat.subprocess. --- doc/api/api_changes.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/api/api_changes.rst b/doc/api/api_changes.rst index d6761a790027..82c3d0640533 100644 --- a/doc/api/api_changes.rst +++ b/doc/api/api_changes.rst @@ -32,6 +32,13 @@ Changes in 1.3.x by ``self.vline`` for vertical cursors lines and ``self.hline`` is added for the horizontal cursors lines. +* On POSIX platforms, the :func:`~matplotlib.cbook.report_memory` function + raises :class:`NotImplementedError` instead of :class:`OSError` if the + :command:`ps` command cannot be run. + +* The :func:`~matplotlib.cbook.check_output` function has been moved to + `~matplotlib.compat.subprocess`. + Changes in 1.2.x ================ From 03cddc8c05bb7a1a18114f72eec72b27d5f5ed4d Mon Sep 17 00:00:00 2001 From: Matt Giuca Date: Wed, 20 Mar 2013 10:20:50 +1100 Subject: [PATCH 8/8] compat.subprocess: Turn on absolute importing. This prevents the module from importing itself (as opposed to the global subprocess module) on Python 3 after 2to3 conversion. --- lib/matplotlib/compat/subprocess.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/compat/subprocess.py b/lib/matplotlib/compat/subprocess.py index 62cff86d869f..5f77c4f8ec0d 100644 --- a/lib/matplotlib/compat/subprocess.py +++ b/lib/matplotlib/compat/subprocess.py @@ -13,6 +13,7 @@ This module is safe to import from anywhere within matplotlib. """ +from __future__ import absolute_import # Required to import subprocess from __future__ import print_function import subprocess