From e16d973849104cfff72438d9e77857046454e58b Mon Sep 17 00:00:00 2001
From: Christoph Groth <christoph.groth@cea.fr>
Date: Mon, 14 Nov 2016 16:36:52 +0100
Subject: [PATCH] setup.py: add numpy include dir to each command's include_dir
 option

Before we used the include_dir argument to setup(), but this caused problems:
https://gitlab.kwant-project.org/kwant/kwant/issues/48
---
 setup.py | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/setup.py b/setup.py
index 472cd7b7..6f1b1d65 100755
--- a/setup.py
+++ b/setup.py
@@ -541,6 +541,17 @@ def main():
          dict(sources=['kwant/linalg/_mumps.pyx'],
               depends=['kwant/linalg/cmumps.pxd']))])
 
+    # Add NumPy header path to include_dirs of all the extensions.
+    try:
+        import numpy
+    except ImportError:
+        print(banner(' Caution '), 'NumPy header directory cannot be determined'
+              ' ("import numpy" failed).', banner(), sep='\n', file=sys.stderr)
+    else:
+        numpy_include = numpy.get_include()
+        for ext in exts.values():
+            ext.setdefault('include_dirs', []).append(numpy_include)
+
     aliases = [('lapack', 'kwant.linalg.lapack'),
                ('mumps', 'kwant.linalg._mumps')]
 
@@ -553,13 +564,6 @@ def main():
     exts = configure_special_extensions(exts, build_summary)
     exts = maybe_cythonize(exts)
 
-    try:
-        import numpy
-    except ImportError:
-        numpy_include_dirs = []
-    else:
-        numpy_include_dirs = [numpy.get_include()]
-
     classifiers = """\
         Development Status :: 5 - Production/Stable
         Intended Audience :: Science/Research
@@ -589,7 +593,6 @@ def main():
                     'build_ext': kwant_build_ext,
                     'build_tut': kwant_build_tut},
           ext_modules=exts,
-          include_dirs=numpy_include_dirs,
           setup_requires=['pytest-runner >= 2.7'],
           tests_require=['numpy > 1.6.1', 'pytest >= 2.6.3'],
           install_requires=['numpy > 1.6.1', 'scipy >= 0.11.0', 'tinyarray'],
-- 
GitLab