Skip to content

Commit 15d09a5

Browse files
committed
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.
1 parent 8863ace commit 15d09a5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/matplotlib/compat/subprocess.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,25 @@
1818

1919
import subprocess
2020

21-
__all__ = ['Popen', 'PIPE', 'STDOUT', 'check_output']
21+
__all__ = ['Popen', 'PIPE', 'STDOUT', 'check_output', 'CalledProcessError']
2222

2323

2424
if hasattr(subprocess, 'Popen'):
2525
Popen = subprocess.Popen
2626
# Assume that it also has the other constants.
2727
PIPE = subprocess.PIPE
2828
STDOUT = subprocess.STDOUT
29+
CalledProcessError = subprocess.CalledProcessError
2930
else:
3031
# In restricted environments (such as Google App Engine), these are
3132
# non-existent. Replace them with dummy versions that always raise OSError.
3233
def Popen(*args, **kwargs):
3334
raise OSError("subprocess.Popen is not supported")
3435
PIPE = -1
3536
STDOUT = -2
37+
# There is no need to catch CalledProcessError. These stubs cannot raise
38+
# it. None in an except clause will simply not match any exceptions.
39+
CalledProcessError = None
3640

3741

3842
def _check_output(*popenargs, **kwargs):
@@ -75,5 +79,3 @@ def _check_output(*popenargs, **kwargs):
7579
check_output = subprocess.check_output
7680
else:
7781
check_output = _check_output
78-
79-
CalledProcessError = subprocess.CalledProcessError

0 commit comments

Comments
 (0)