1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-07-22 10:47:43 +02:00

build Python module using pythonic distutils

This commit is contained in:
q-posev 2021-07-26 18:43:15 +02:00
parent 4faee98092
commit 8c6289a8ba
2 changed files with 49 additions and 9 deletions

View File

@ -180,24 +180,37 @@ cppcheck.out: $(trexio_h)
-I../include *.c *.h 2>../$@
python: src/_pytrexio.so
python: src/_pytrexio*.so
python-test: src/test.py src/_pytrexio.so
python-test: src/test.py src/_pytrexio*.so
cd src/ && python3 test.py
$(RM) -r -- src/__pycache__
src/_pytrexio.so: $(ORG_FILES) $(trexio_h) src/pytrexio.i
# Advanced compilation using Python-native distutils
#
# swig -python -threads pytrexio.i ----> Add thread support for all the interface
#
src/_pytrexio*.so: $(ORG_FILES) $(trexio_h) src/pytrexio.i
cp $(trexio_h) src/
cd src/ && \
swig -python -o pytrexio_wrap.c pytrexio.i && \
$(CC) $(CPPFLAGS) -I/usr/include/python3.8 -fPIC -Wno-discarded-qualifiers \
-c trexio.c trexio_hdf5.c trexio_text.c pytrexio_wrap.c && \
$(CC) -shared trexio.o trexio_hdf5.o trexio_text.o pytrexio_wrap.o \
$(LDFLAGS) $(LIBS) -o _pytrexio.so
swig -python -py3 -o pytrexio_wrap.c pytrexio.i && \
python3 setup.py build_ext --inplace --swig-opts="-modern"
$(RM) -- src/trexio.h
# Manual compilation of Python module
#
#src/_pytrexio.so: $(ORG_FILES) $(trexio_h) src/pytrexio.i
# cp $(trexio_h) src/
# cd src/ && \
# swig -python -py3 -o pytrexio_wrap.c pytrexio.i && \
# $(CC) $(CPPFLAGS) -I/usr/include/python3.8 -fPIC -Wno-discarded-qualifiers \
# -c trexio.c trexio_hdf5.c trexio_text.c pytrexio_wrap.c && \
# $(CC) -shared trexio.o trexio_hdf5.o trexio_text.o pytrexio_wrap.o \
# $(LDFLAGS) $(LIBS) -o _pytrexio.so
# $(RM) -- src/trexio.h
#
CLEANFILES += src/pytrexio_wrap.c src/pytrexio.py src/_pytrexio.so
CLEANFILES += src/pytrexio_wrap.c src/pytrexio.py src/_pytrexio*.so
.PHONY: cppcheck python python-test

27
src/setup.py Normal file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env python
"""
setup.py file for pytrexio
"""
from distutils.core import setup, Extension
pytrexio_module = Extension('_pytrexio',
sources=['trexio.c', 'trexio_hdf5.c', 'trexio_text.c', 'pytrexio_wrap.c'],
include_dirs=['/usr/include/hdf5/serial'],
#runtime_library_dirs=['/usr/lib/x86_64-linux-gnu/hdf5/serial'],
libraries=['hdf5', 'hdf5_hl'],
#extra_compile_args=['-I/usr/include/hdf5/serial'],
extra_link_args=['-L/usr/lib/x86_64-linux-gnu/hdf5/serial']
)
setup (name = 'pytrexio',
version = '0.1',
author = "TREX-CoE",
description = """Python API of the TREXIO library""",
ext_modules = [pytrexio_module],
py_modules = ["pytrexio"],
url='https://github.com/TREX-CoE/trexio',
packages=['distutils', 'distutils.command'],
)