1import sys
2
3if 'setuptools' in sys.modules:
4    try:
5        from setuptools.command.build_ext import build_ext as _build_ext
6    except ImportError:
7        # We may be in the process of importing setuptools, which tries
8        # to import this.
9        from distutils.command.build_ext import build_ext as _build_ext
10else:
11    from distutils.command.build_ext import build_ext as _build_ext
12
13
14class new_build_ext(_build_ext, object):
15    def finalize_options(self):
16        if self.distribution.ext_modules:
17            nthreads = getattr(self, 'parallel', None)  # -j option in Py3.5+
18            nthreads = int(nthreads) if nthreads else None
19            from Cython.Build.Dependencies import cythonize
20            self.distribution.ext_modules[:] = cythonize(
21                self.distribution.ext_modules, nthreads=nthreads, force=self.force)
22        super(new_build_ext, self).finalize_options()
23
24# This will become new_build_ext in the future.
25from .old_build_ext import old_build_ext as build_ext
26