Skip to content

Commit

Permalink
Fixes issue #144.
Browse files Browse the repository at this point in the history
As per the method documented by ead at https://stackoverflow.com/a/54138355
this delays the numpy.get_include() call until after after the packages listed
in setup_requires are installed.
  • Loading branch information
mrshannon committed Feb 1, 2019
1 parent ea5cde8 commit 1b9afd7
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
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,21 @@ 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 +117,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 +135,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 1b9afd7

Please sign in to comment.