1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-08-25 06:31:43 +02:00

FIX: bug related to import numpy in setup.py script

use the custom NUMPY_INCLUDEDIR environment variable derived from a call to numpy.get_include
This commit is contained in:
q-posev 2021-09-09 15:09:26 +02:00
parent 58b611e21b
commit b9c3ddb30e
3 changed files with 32 additions and 5 deletions

View File

@ -1 +1 @@
include src/*.c src/trexio*.h
include src/*.c src/trexio*.h examples/*.ipynb requirements.txt set_NUMPY_INCLUDEDIR.sh

4
python/set_NUMPY_INCLUDEDIR.sh Executable file
View File

@ -0,0 +1,4 @@
INCLUDEDIR=`python -c 'import numpy; print(numpy.get_include())'`
export NUMPY_INCLUDEDIR=${INCLUDEDIR}

View File

@ -1,15 +1,36 @@
#!/usr/bin/env python3
"""
setup.py file for TREXIO Python package
"""
from distutils.sysconfig import get_python_inc
from setuptools import setup, Extension
import os
from setuptools import setup, Extension
# this was recommended to solve the problem of the missing numpy header files
# bit it causes `pip install .` to fail with numpy module not found error
#try:
# import numpy
#except ImportError:
# raise Exception("numpy Python package cannot be imported.")
#numpy_includedir = numpy.get_include()
# this does not cause aforementioned issue but the includedir points to system-wide numpy and not to venv-wide
#from distutils.sysconfig import get_python_inc
#numpy_includedir = os.path.join(get_python_inc(plat_specific=1), 'numpy')
# dirty workaround: get numpy includedir from the environment variable that can be pre-set using set_NUMPY_INCLUDEDIR.sh
numpy_includedir = os.environ.get("NUMPY_INCLUDEDIR", None)
numpy_isUndefined = numpy_includedir is None or numpy_includedir==""
if numpy_isUndefined:
raise Exception("NUMPY_INCLUDEDIR environment variable is not specified. Please do it manually or execute set_NUMPY_INCLUDEDIR.sh script.")
rootpath = os.path.dirname(os.path.abspath(__file__))
srcpath = os.path.join(rootpath, 'src')
c_files = ['trexio.c', 'trexio_hdf5.c', 'trexio_text.c', 'pytrexio_wrap.c']
numpy_includedir = os.path.join(get_python_inc(plat_specific=1), 'numpy')
with open("README.md", "r") as fh:
long_description = fh.read()
@ -40,7 +61,7 @@ if h5_ldflags_isUndefined or h5_cflags_isUndefined:
try:
import pkgconfig as pk
except ImportError:
raise Exception("pkgconfig Python package has not been found")
raise Exception("pkgconfig Python package cannot be imported.")
try:
assert pk.exists('hdf5')
@ -91,6 +112,8 @@ setup(name = 'trexio',
"Operating System :: Unix",
"Operating System :: MacOS"
],
python_requires = ">=3.6",
setup_requires = ['numpy', 'pkgconfig'],
install_requires = ['numpy']
)