Issue #5309: distutils' build and build_ext commands now accept a ``-j``
option to enable parallel building of extension modules.
diff --git a/setup.py b/setup.py
index 4691793..016c455 100644
--- a/setup.py
+++ b/setup.py
@@ -25,6 +25,11 @@
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 @@
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 @@
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 @@
(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: