Issue #5309: distutils' build and build_ext commands now accept a `-j`

option to enable parallel building of extension modules.
This commit is contained in:
Antoine Pitrou 2014-09-26 23:31:59 +02:00
parent 7e23d82cec
commit 2c0a916061
6 changed files with 117 additions and 28 deletions

View file

@ -25,6 +25,11 @@ cflags = sysconfig.get_config_var('CFLAGS')
py_cflags_nodist = sysconfig.get_config_var('PY_CFLAGS_NODIST')
sysconfig.get_config_vars()['CFLAGS'] = cflags + ' ' + py_cflags_nodist
class Dummy:
"""Hack for parallel build"""
ProcessPoolExecutor = None
sys.modules['concurrent.futures.process'] = Dummy
def get_platform():
# cross build
if "_PYTHON_HOST_PLATFORM" in os.environ:
@ -174,6 +179,8 @@ class PyBuildExt(build_ext):
build_ext.__init__(self, dist)
self.failed = []
self.failed_on_import = []
if '-j' in os.environ.get('MAKEFLAGS', ''):
self.parallel = True
def build_extensions(self):
@ -253,6 +260,9 @@ class PyBuildExt(build_ext):
build_ext.build_extensions(self)
for ext in self.extensions:
self.check_extension_import(ext)
longest = max([len(e.name) for e in self.extensions])
if self.failed or self.failed_on_import:
all_failed = self.failed + self.failed_on_import
@ -305,6 +315,15 @@ class PyBuildExt(build_ext):
(ext.name, sys.exc_info()[1]))
self.failed.append(ext.name)
return
def check_extension_import(self, ext):
# Don't try to import an extension that has failed to compile
if ext.name in self.failed:
self.announce(
'WARNING: skipping import check for failed build "%s"' %
ext.name, level=1)
return
# Workaround for Mac OS X: The Carbon-based modules cannot be
# reliably imported into a command-line Python
if 'Carbon' in ext.extra_link_args: