Skip to content

Commit

Permalink
Allow setup.py without numpy being pre-installed. (#145)
Browse files Browse the repository at this point in the history
Fixes issue #144.
  • Loading branch information
pelson committed Feb 2, 2019
2 parents ea5cde8 + baba1fa commit 90c705f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions setup.py
Expand Up @@ -4,7 +4,6 @@
import sys

from distutils.sysconfig import get_config_var
import numpy as np
from setuptools import Command, Extension, find_packages, setup
import versioneer

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


def numpy_build_ext(pars):
from setuptools.command.build_ext import build_ext as _build_ext

class build_ext(_build_ext):
def finalize_options(self):
_build_ext.finalize_options(self)
__builtins__.__NUMPY_SETUP__ = False
import numpy
self.include_dirs.append(numpy.get_include())

return build_ext(pars)


udunits_ext = Extension('cf_units._udunits2',
['cf_units/_udunits2.{}'.format(ext)],
include_dirs=include_dirs + [np.get_include()],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=['udunits2'],
define_macros=DEFINE_MACROS,
Expand All @@ -106,7 +119,7 @@ def long_description():
compiler_directives=COMPILER_DIRECTIVES,
language_level=2)

cmdclass = {'clean_cython': CleanCython}
cmdclass = {'clean_cython': CleanCython, 'build_ext': numpy_build_ext}
cmdclass.update(versioneer.get_cmdclass())

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

0 comments on commit 90c705f

Please sign in to comment.