From 15d09a59004ed522cef19df7b08db39e4af22f88 Mon Sep 17 00:00:00 2001 From: Dara Adib Date: Mon, 3 Mar 2014 10:21:13 -0800 Subject: [PATCH] Work around subprocess.CalledProcessError on Google App Engine Set subprocess.CalledProcessError to None on restrictive environments like Google App Engine because the exception cannot be raised and there is no need to catch it. Fixes #1825 which broke after #1857. --- lib/matplotlib/compat/subprocess.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/compat/subprocess.py b/lib/matplotlib/compat/subprocess.py index 6918e7d78be0..9b5b516a68c2 100644 --- a/lib/matplotlib/compat/subprocess.py +++ b/lib/matplotlib/compat/subprocess.py @@ -18,7 +18,7 @@ import subprocess -__all__ = ['Popen', 'PIPE', 'STDOUT', 'check_output'] +__all__ = ['Popen', 'PIPE', 'STDOUT', 'check_output', 'CalledProcessError'] if hasattr(subprocess, 'Popen'): @@ -26,6 +26,7 @@ # Assume that it also has the other constants. PIPE = subprocess.PIPE STDOUT = subprocess.STDOUT + CalledProcessError = subprocess.CalledProcessError else: # In restricted environments (such as Google App Engine), these are # non-existent. Replace them with dummy versions that always raise OSError. @@ -33,6 +34,9 @@ def Popen(*args, **kwargs): raise OSError("subprocess.Popen is not supported") PIPE = -1 STDOUT = -2 + # There is no need to catch CalledProcessError. These stubs cannot raise + # it. None in an except clause will simply not match any exceptions. + CalledProcessError = None def _check_output(*popenargs, **kwargs): @@ -75,5 +79,3 @@ def _check_output(*popenargs, **kwargs): check_output = subprocess.check_output else: check_output = _check_output - -CalledProcessError = subprocess.CalledProcessError