Skip to content

Commit 90c705f

Browse files
authored
Allow setup.py without numpy being pre-installed. (#145)
Fixes issue #144.
2 parents ea5cde8 + baba1fa commit 90c705f

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

setup.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import sys
55

66
from distutils.sysconfig import get_config_var
7-
import numpy as np
87
from setuptools import Command, Extension, find_packages, setup
98
import versioneer
109

@@ -93,9 +92,23 @@ def long_description():
9392
sys.argv.remove(FLAG_COVERAGE)
9493
print('enable: "linetrace" Cython compiler directive')
9594

95+
96+
def numpy_build_ext(pars):
97+
from setuptools.command.build_ext import build_ext as _build_ext
98+
99+
class build_ext(_build_ext):
100+
def finalize_options(self):
101+
_build_ext.finalize_options(self)
102+
__builtins__.__NUMPY_SETUP__ = False
103+
import numpy
104+
self.include_dirs.append(numpy.get_include())
105+
106+
return build_ext(pars)
107+
108+
96109
udunits_ext = Extension('cf_units._udunits2',
97110
['cf_units/_udunits2.{}'.format(ext)],
98-
include_dirs=include_dirs + [np.get_include()],
111+
include_dirs=include_dirs,
99112
library_dirs=library_dirs,
100113
libraries=['udunits2'],
101114
define_macros=DEFINE_MACROS,
@@ -106,7 +119,7 @@ def long_description():
106119
compiler_directives=COMPILER_DIRECTIVES,
107120
language_level=2)
108121

109-
cmdclass = {'clean_cython': CleanCython}
122+
cmdclass = {'clean_cython': CleanCython, 'build_ext': numpy_build_ext}
110123
cmdclass.update(versioneer.get_cmdclass())
111124

112125
description = ('Units of measure as required by the Climate and Forecast (CF) '
@@ -124,7 +137,7 @@ def long_description():
124137
package_data={'cf_units': list(file_walk_relative('cf_units/etc',
125138
remove='cf_units/'))},
126139
install_requires=load('requirements.txt'),
127-
setup_requires=['pytest-runner'],
140+
setup_requires=['pytest-runner', 'numpy'],
128141
tests_require=load('requirements-dev.txt'),
129142
test_suite='cf_units.tests',
130143
cmdclass=cmdclass,

0 commit comments

Comments
 (0)