From 1693de51cc43057cbab749f2f7e8dac121fc4454 Mon Sep 17 00:00:00 2001 From: "Konstantin (Tino) Sering" Date: Tue, 6 Feb 2018 13:21:02 +0100 Subject: [PATCH] boot straps numpy and uses cython implicitly --- setup.py | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/setup.py b/setup.py index f4b1ab3..e6947d9 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,18 @@ from setuptools import setup, Extension +from setuptools.command.build_ext import build_ext as _build_ext + +# Do not import cython as this will be done py setuptools automagically + +# boot strap numpy +# https://stackoverflow.com/questions/19919905/how-to-bootstrap-numpy-installation-in-setup-py +class build_ext(_build_ext): + def finalize_options(self): + _build_ext.finalize_options(self) + # Prevent numpy from thinking it is still in its setup process: + __builtins__.__NUMPY_SETUP__ = False + import numpy + self.include_dirs.append(numpy.get_include()) -# While setup, this file will be called twice: -# One time, to read the dependencies, -# and after their installation. -try: - from Cython.Distutils import build_ext - import numpy -except ImportError as e: - use_deps = False -else: - use_deps = True pkg = __import__('pyndl') @@ -27,20 +30,16 @@ def load_requirements(fn): return [x.rstrip() for x in list(f) if x and not x.startswith('#')] -if use_deps: - ext_modules = [ - Extension( - "pyndl.ndl_parallel", - ["pyndl/ndl_parallel.pyx"], - extra_compile_args=['-fopenmp'], - extra_link_args=['-fopenmp'], - include_dirs=[numpy.get_include()] - ) - ] - cmdclass = {'build_ext': build_ext} -else: - ext_modules = [] - cmdclass = {} +ext_modules = [ + Extension( + "pyndl.ndl_parallel", + ["pyndl/ndl_parallel.pyx"], + extra_compile_args=['-fopenmp'], + extra_link_args=['-fopenmp'], + #include_dirs=[numpy.get_include()] # this is dealt with in the boot strap class + ) +] + setup( name='pyndl', @@ -54,6 +53,7 @@ def load_requirements(fn): classifiers=classifiers, platforms='Linux', packages=['pyndl'], + setup_requires=['numpy', 'Cython'], install_requires=load_requirements('requirements.txt'), extras_require={ 'tests': [ @@ -66,5 +66,5 @@ def load_requirements(fn): 'numpydoc', 'easydev==0.9.35']}, ext_modules=ext_modules, - cmdclass=cmdclass + cmdclass={'build_ext': build_ext} )