8000 Fix build on Python 2.6 · matplotlib/matplotlib@7db8fe2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7db8fe2

Browse files
committed
Fix build on Python 2.6
1 parent 4d8c846 commit 7db8fe2

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

setupext.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,39 @@
1212
from textwrap import fill
1313

1414

15+
try:
16+
from subprocess import check_output
17+
except ImportError:
18+
# check_output is not available in Python 2.6
19+
def check_output(*popenargs, **kwargs):
20+
"""
21+
Run command with arguments and return its output as a byte
22+
string.
23+
24+
Backported from Python 2.7 as it's implemented as pure python
25+
on stdlib.
26+
"""
27+
process = subprocess.Popen(
28+
stdout=subprocess.PIPE, *popenargs, **kwargs)
29+
output, unused_err = process.communicate()
30+
retcode = process.poll()
31+
if retcode:
32+
cmd = kwargs.get("args")
33+
if cmd is None:
34+
cmd = popenargs[0]
35+
error = subprocess.CalledProcessError(retcode, cmd)
36+
error.output = output
37+
raise error
38+
return output
39+
40+
1541
if sys.platform != 'win32':
1642
if sys.version_info[0] < 3:
1743
from commands import getstatusoutput
1844
else:
1945
from subprocess import getstatusoutput
2046

47+
2148
if sys.version_info[0] < 3:
2249
import ConfigParser as configparser
2350
else:
@@ -249,7 +276,7 @@ def setup_extension(self, ext, package, default_include_dirs=[],
249276
use_defaults = True
250277
if self.has_pkgconfig:
251278
try:
252-
output = subprocess.check_output(command, shell=True)
279+
output = check_output(command, shell=True)
253280
except subprocess.CalledProcessError:
254281
pass
255282
else:

0 commit comments

Comments
 (0)
0