|
1 |
| -from setuptools import Extension |
2 |
| -from setuptools.command.build_ext import build_ext as _build_ext |
| 1 | +import os |
| 2 | +import shutil |
3 | 3 | import sys
|
| 4 | +from distutils.core import Distribution, Extension |
4 | 5 |
|
| 6 | +from Cython.Build import build_ext, cythonize |
| 7 | +import numpy |
5 | 8 |
|
6 |
| -# bootstrap numpy |
7 |
| -# https://stackoverflow.com/questions/19919905/how-to-bootstrap-numpy-installation-in-setup-py |
8 |
| -class build_ext(_build_ext): |
9 |
| - def finalize_options(self): |
10 |
| - _build_ext.finalize_options(self) |
11 |
| - # Prevent numpy from thinking it is still in its setup process: |
12 |
| - #__builtins__.__NUMPY_SETUP__ = False |
13 |
| - import numpy |
14 |
| - self.include_dirs.append(numpy.get_include()) |
| 9 | +cython_dir = "pyndl" |
15 | 10 |
|
| 11 | +ndl_parallel = Extension("pyndl.ndl_parallel", |
| 12 | + ["pyndl/ndl_parallel.pyx"], |
| 13 | + include_dirs=[numpy.get_include()]) |
| 14 | +ndl_openmp = Extension("pyndl.ndl_openmp", |
| 15 | + ["pyndl/ndl_openmp.pyx"], |
| 16 | + extra_compile_args=['-fopenmp'], |
| 17 | + extra_link_args=['-fopenmp'], |
| 18 | + include_dirs=[numpy.get_include()]) |
| 19 | +corr_parallel = Extension("pyndl.correlation_openmp", |
| 20 | + ["pyndl/correlation_openmp.pyx"], |
| 21 | + extra_compile_args=['-fopenmp'], |
| 22 | + extra_link_args=['-fopenmp'], |
| 23 | + include_dirs=[numpy.get_include()]) |
16 | 24 |
|
17 |
| -ndl_parallel = Extension("pyndl.ndl_parallel", ["pyndl/ndl_parallel.pyx"]) |
18 |
| -ndl_openmp = Extension("pyndl.ndl_openmp", ["pyndl/ndl_openmp.pyx"], |
19 |
| - extra_compile_args=['-fopenmp'], extra_link_args=['-fopenmp']) |
20 |
| -corr_parallel = Extension("pyndl.correlation_openmp", ["pyndl/correlation_openmp.pyx"], |
21 |
| - extra_compile_args=['-fopenmp'], extra_link_args=['-fopenmp']) |
22 |
| -# by giving ``cython`` as ``install_requires`` this will be ``cythonized`` |
23 |
| -# automagically |
24 |
| - |
25 |
| -ext_modules = [] |
| 25 | +extensions = [] |
| 26 | +include_paths = [] |
26 | 27 | if sys.platform.startswith('linux'):
|
27 |
| - ext_modules = [ndl_parallel, ndl_openmp, corr_parallel] |
| 28 | + extensions = [ndl_parallel, ndl_openmp, corr_parallel] |
| 29 | + include_paths = [cython_dir, cython_dir, cython_dir] |
28 | 30 | elif sys.platform.startswith('win32'):
|
29 |
| - ext_modules = [ndl_parallel] # skip openmp installation on windows for now |
| 31 | + extensions = [ndl_parallel] # skip openmp installation on windows for now |
| 32 | + include_paths = [cython_dir] |
30 | 33 | elif sys.platform.startswith('darwin'):
|
31 |
| - ext_modules = [ndl_parallel] # skip openmp installation on macos for now |
| 34 | + extensions = [ndl_parallel] # skip openmp installation on macos for now |
| 35 | + include_paths = [cython_dir] |
| 36 | + |
| 37 | +ext_modules = cythonize(extensions, include_path=include_paths) |
| 38 | +dist = Distribution({"ext_modules": ext_modules}) |
| 39 | +cmd = build_ext(dist) |
| 40 | +cmd.ensure_finalized() |
| 41 | +cmd.run() |
32 | 42 |
|
| 43 | +for output in cmd.get_outputs(): |
| 44 | + relative_extension = os.path.relpath(output, cmd.build_lib) |
| 45 | + shutil.copyfile(output, relative_extension) |
33 | 46 |
|
34 |
| -def build(setup_kwargs): |
35 |
| - """ |
36 |
| - This function is mandatory in order to build the extensions. |
37 |
| - """ |
38 |
| - setup_kwargs.update({ |
39 |
| - 'ext_modules': ext_modules, |
40 |
| - 'cmdclass': { |
41 |
| - 'build_ext': build_ext |
42 |
| - } |
43 |
| - }) |
|
0 commit comments