mirror of
https://github.com/TREX-CoE/trexio.git
synced 2025-01-05 11:00:30 +01: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:
parent
58b611e21b
commit
b9c3ddb30e
@ -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
4
python/set_NUMPY_INCLUDEDIR.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
INCLUDEDIR=`python -c 'import numpy; print(numpy.get_include())'`
|
||||||
|
export NUMPY_INCLUDEDIR=${INCLUDEDIR}
|
||||||
|
|
@ -1,15 +1,36 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
"""
|
"""
|
||||||
setup.py file for TREXIO Python package
|
setup.py file for TREXIO Python package
|
||||||
"""
|
"""
|
||||||
from distutils.sysconfig import get_python_inc
|
|
||||||
from setuptools import setup, Extension
|
|
||||||
import os
|
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__))
|
rootpath = os.path.dirname(os.path.abspath(__file__))
|
||||||
srcpath = os.path.join(rootpath, 'src')
|
srcpath = os.path.join(rootpath, 'src')
|
||||||
c_files = ['trexio.c', 'trexio_hdf5.c', 'trexio_text.c', 'pytrexio_wrap.c']
|
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:
|
with open("README.md", "r") as fh:
|
||||||
long_description = fh.read()
|
long_description = fh.read()
|
||||||
@ -40,7 +61,7 @@ if h5_ldflags_isUndefined or h5_cflags_isUndefined:
|
|||||||
try:
|
try:
|
||||||
import pkgconfig as pk
|
import pkgconfig as pk
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise Exception("pkgconfig Python package has not been found")
|
raise Exception("pkgconfig Python package cannot be imported.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
assert pk.exists('hdf5')
|
assert pk.exists('hdf5')
|
||||||
@ -91,6 +112,8 @@ setup(name = 'trexio',
|
|||||||
"Operating System :: Unix",
|
"Operating System :: Unix",
|
||||||
"Operating System :: MacOS"
|
"Operating System :: MacOS"
|
||||||
],
|
],
|
||||||
|
python_requires = ">=3.6",
|
||||||
|
setup_requires = ['numpy', 'pkgconfig'],
|
||||||
install_requires = ['numpy']
|
install_requires = ['numpy']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user