From 8c6289a8bae512aed10db7a7a75a984e52fb181e Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 26 Jul 2021 18:43:15 +0200 Subject: [PATCH] build Python module using pythonic distutils --- Makefile.am | 31 ++++++++++++++++++++++--------- src/setup.py | 27 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 src/setup.py diff --git a/Makefile.am b/Makefile.am index c7b2f1e..bc3e06e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/setup.py b/src/setup.py new file mode 100644 index 0000000..ca9335d --- /dev/null +++ b/src/setup.py @@ -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'], + )