Skip to content

Commit

Permalink
Fall-back to querying numpy for inc dir (#807)
Browse files Browse the repository at this point in the history
We changed to check site_packages for numpy's inc dir to avoid having to
import numpy at setup.py invocation. That's great, but in some
environments that means we will not find numpy correctly.

This doesn't change initial behavior, but at the point where we used to
give up and fail to install it will now attempt to import numpy to find
the inc path. If numpy fails to import then we back out as before.
  • Loading branch information
jabooth authored and Patrick Snape committed Jun 15, 2017
1 parent 5b369a6 commit 62af286
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
IS_WIN = 'windows' == SYS_PLATFORM

# Get Numpy include path without importing it
NUMPY_INC_PATHS = [os.path.join(r, 'numpy', 'core', 'include')
for r in site.getsitepackages() if
NUMPY_INC_PATHS = [os.path.join(r, 'numpy', 'core', 'include')
for r in site.getsitepackages() if
os.path.isdir(os.path.join(r, 'numpy', 'core', 'include'))]
if len(NUMPY_INC_PATHS) == 0:
raise ValueError("Could not find numpy include dir - cannot proceed with "
"compilation of cython modules.")
try:
import numpy as np
except ImportError:
raise ValueError("Could not find numpy include dir and numpy not installed before build - "
"cannot proceed with compilation of cython modules.")
else:
# just ask numpy for it's include dir
NUMPY_INC_PATHS = [np.get_include()]

elif len(NUMPY_INC_PATHS) > 1:
print("Found {} numpy include dirs: "
"{}".format(len(NUMPY_INC_PATHS), ', '.join(NUMPY_INC_PATHS)))
Expand Down

0 comments on commit 62af286

Please sign in to comment.