mirror of
https://github.com/TREX-CoE/trexio.git
synced 2025-01-03 10:06:01 +01:00
pytrexio build and pip install working
This commit is contained in:
parent
bb18a9c826
commit
d0c19e0ce0
69
Makefile.am
69
Makefile.am
@ -137,7 +137,7 @@ tests_test_f_SOURCES = $(test_trexio_f) tests/test_f.f90
|
|||||||
tests_test_f_LDFLAGS = -no-install
|
tests_test_f_LDFLAGS = -no-install
|
||||||
|
|
||||||
clean-local:
|
clean-local:
|
||||||
-rm -rf -- *.dir/ *.h5
|
-rm -rf -- *.dir/ *.h5 __pycache__/
|
||||||
|
|
||||||
# =============== DOCUMENTATION =============== #
|
# =============== DOCUMENTATION =============== #
|
||||||
|
|
||||||
@ -184,60 +184,43 @@ cppcheck.out: $(trexio_h)
|
|||||||
-I../include *.c *.h 2>../$@
|
-I../include *.c *.h 2>../$@
|
||||||
|
|
||||||
|
|
||||||
setup_py = $(srcdir)/setup.py
|
setup_py = $(srcdir)/python/setup.py
|
||||||
setup_cfg = $(srcdir)/setup.cfg
|
setup_cfg = $(srcdir)/python/setup.cfg
|
||||||
pytrexio_py = $(srcdir)/src/pytrexio.py
|
pytrexio_py = $(srcdir)/python/pytrexio.py
|
||||||
pytrexio_c = $(srcdir)/src/pytrexio_wrap.c
|
TESTS_PY = $(srcdir)/python/test/test_py.py
|
||||||
pytrexio_i = $(srcdir)/src/pytrexio.i
|
pytrexio_c = $(srcdir)/src/pytrexio_wrap.c
|
||||||
TESTS_PY = $(srcdir)/tests/test_py.py
|
pytrexio_i = $(srcdir)/src/pytrexio.i
|
||||||
|
numpy_i = $(srcdir)/src/numpy.i
|
||||||
|
|
||||||
#python-prepare:
|
|
||||||
# cp include/trexio.h src/*.c src/*.h python/src/
|
|
||||||
|
|
||||||
python: _pytrexio*.so
|
python-test: $(pytrexio_py) $(TESTS_PY)
|
||||||
|
|
||||||
python-test: $(TESTS_PY) $(pytrexio_py)
|
|
||||||
cp $(pytrexio_py) .
|
|
||||||
python3 $(TESTS_PY)
|
python3 $(TESTS_PY)
|
||||||
$(RM) -r -- __pycache__ pytrexio.py
|
$(RM) -r -- __pycache__
|
||||||
|
|
||||||
python-sdist: $(setup_py) $(pytrexio_py)
|
python-install: $(pytrexio_py) $(setup_py) $(setup_cfg)
|
||||||
python3 setup.py sdist
|
cd python && ./install_pytrexio.sh
|
||||||
|
|
||||||
python-build: $(setup_py) $(pytrexio_py) pyproject.toml
|
$(pytrexio_py): $(pytrexio_c)
|
||||||
python3 -m build
|
cd tools && ./prepare_python.sh
|
||||||
|
|
||||||
python-release: $(setup_py) $(pytrexio_py) pyproject.toml
|
# Build Python module and C wrapper code for TREXIO using SWIG
|
||||||
python3 -m twine upload --repository testpypi dist/*
|
# [?] swig -python -threads pytrexio.i ----> Add thread support for all the interface
|
||||||
|
$(pytrexio_c): $(ORG_FILES) $(trexio_h) $(pytrexio_i) $(numpy_i)
|
||||||
# Advanced compilation using Python-native distutils
|
|
||||||
#
|
|
||||||
# swig -python -threads pytrexio.i ----> Add thread support for all the interface
|
|
||||||
#
|
|
||||||
$(pytrexio_c): $(ORG_FILES) $(trexio_h) $(pytrexio_i)
|
|
||||||
cp $(trexio_h) src/
|
cp $(trexio_h) src/
|
||||||
cd src/ && swig -python -py3 -o pytrexio_wrap.c pytrexio.i
|
cd src/ && swig -python -py3 -o pytrexio_wrap.c pytrexio.i
|
||||||
|
|
||||||
_pytrexio*.so: $(pytrexio_c) $(setup_py)
|
|
||||||
python3 setup.py build_ext --inplace --swig-opts="-modern"
|
|
||||||
$(RM) -- src/trexio.h
|
$(RM) -- src/trexio.h
|
||||||
|
|
||||||
# Manual compilation of Python module
|
$(numpy_i):
|
||||||
#
|
wget https://raw.githubusercontent.com/numpy/numpy/main/tools/swig/numpy.i -O $(numpy_i)
|
||||||
#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 _pytrexio*.so
|
|
||||||
|
|
||||||
.PHONY: cppcheck python python-build python-test python-release
|
CLEANFILES += src/pytrexio_wrap.c \
|
||||||
|
src/pytrexio.py \
|
||||||
|
python/pytrexio.py \
|
||||||
|
python/src/*.c \
|
||||||
|
python/src/*.h
|
||||||
|
|
||||||
|
.PHONY: cppcheck python-test python-install
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
10
python/.gitignore
vendored
Normal file
10
python/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
AUTHORS
|
||||||
|
LICENSE
|
||||||
|
README.md
|
||||||
|
pytrexio.py
|
||||||
|
src/
|
||||||
|
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
*.egg-info/
|
||||||
|
__pycache__/
|
47
python/install_pytrexio.sh
Executable file
47
python/install_pytrexio.sh
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -x
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# This script should update the version of the Python package
|
||||||
|
#source version.py
|
||||||
|
#exit 0
|
||||||
|
|
||||||
|
# Install/upgrade packages required for the installation
|
||||||
|
python3 -m pip install --upgrade setuptools wheel twine
|
||||||
|
|
||||||
|
# Create build directory and compile extension files (*.c)
|
||||||
|
# --no-user-cfg disables custom .cfg files of the user machine, so that only setup.cfg is used
|
||||||
|
python3 -s setup.py --no-user-cfg build
|
||||||
|
|
||||||
|
# Local inplace build of the .so module with SWIG-produced pytrexio_wrap.c (from the SWIG documentation)
|
||||||
|
#python3 setup.py build_ext --inplace --swig-opts="-modern"
|
||||||
|
|
||||||
|
# Create distributions:
|
||||||
|
# 1) sdist produces .tar.gz with all files necessary for manual compilation;
|
||||||
|
# 2) bdist_whell produces .whl wheel distribution (see https://www.python.org/dev/peps/pep-0425/).
|
||||||
|
python3 setup.py sdist bdist_wheel
|
||||||
|
|
||||||
|
# Install pytrexio in the current environment from the aforementioned wheel
|
||||||
|
# --force-reinstall is needed here because build-system pre-installs pytrexio in the environment
|
||||||
|
# but does not install things in the corresponding site-packages directory
|
||||||
|
python3 -m pip install dist/pytrexio-0.1-*.whl --force-reinstall
|
||||||
|
|
||||||
|
# Uninstall pytrexio: this only works from the pytrexio root directory (more likely python/ folder) and only after --force-reinstall
|
||||||
|
#python3 -m pip uninstall pytrexio
|
||||||
|
|
||||||
|
# Test the current release by uploading to TestPyPI sandbox
|
||||||
|
#python3 -m twine upload --repository testpypi dist/pytrexio-*.tar.gz
|
||||||
|
|
||||||
|
# NOTE:I get an error:
|
||||||
|
# Binary wheel 'pytrexio-0.1-cp38-cp38-linux_x86_64.whl' has an unsupported platform tag 'linux_x86_64'.
|
||||||
|
# when uploading the wheel instead of the tar.gz file to testpypi
|
||||||
|
# This is a well-known issue, see https://stackoverflow.com/questions/59451069/binary-wheel-cant-be-uploaded-on-pypi-using-twine
|
||||||
|
# Once fixed both .tar.gz and .whl distribution can be uploaded, meaning that dist/pytrexio-*.tar.gz can be replaced by dist/*
|
||||||
|
|
||||||
|
# Upload updated version of PyTREXIO to PyPI
|
||||||
|
#python3 -m twine upload dist/pytrexio-*.tar.gz
|
||||||
|
|
||||||
|
# Cleaning
|
||||||
|
rm -rf build dist pytrexio.egg-info
|
||||||
|
|
@ -1,27 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -x
|
|
||||||
set -e
|
|
||||||
|
|
||||||
#source version.py
|
|
||||||
|
|
||||||
python3 -m pip install --upgrade setuptools wheel twine
|
|
||||||
#python3 -s setup.py --no-user-cfg build
|
|
||||||
python3 -s setup.py build
|
|
||||||
python3 setup.py sdist bdist_wheel
|
|
||||||
python3 -m pip install dist/pytrexio-0.1-*.whl --force-reinstall
|
|
||||||
|
|
||||||
# remove
|
|
||||||
#python3 -m pip uninstall pytrexio
|
|
||||||
|
|
||||||
#python3 -m twine upload dist/pytrexio-0.1.tar.gz
|
|
||||||
|
|
||||||
# NOTE:I get an error:
|
|
||||||
# Binary wheel 'pytrexio-0.1-cp38-cp38-linux_x86_64.whl' has an unsupported platform tag 'linux_x86_64'.
|
|
||||||
# when uploading the wheel instead of the tar.gz file to testpypi
|
|
||||||
# This is a well-known issue, see https://stackoverflow.com/questions/59451069/binary-wheel-cant-be-uploaded-on-pypi-using-twine
|
|
||||||
|
|
||||||
#python3 -m twine upload --repository testpypi dist/pytrexio-0.1.tar.gz
|
|
||||||
|
|
||||||
rm -rf build pytrexio.egg-info
|
|
||||||
rm -rf dist
|
|
3028
src/numpy.i
Normal file
3028
src/numpy.i
Normal file
File diff suppressed because it is too large
Load Diff
31
tools/prepare_python.sh
Executable file
31
tools/prepare_python.sh
Executable file
@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check that script is executed from tools directory
|
||||||
|
if [[ $(basename $PWD) != "tools" ]] ; then
|
||||||
|
echo "This script should run in the tools directory"
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
TREXIO_ROOT=$(dirname "${PWD}../")
|
||||||
|
|
||||||
|
# First define readonly global variables.
|
||||||
|
readonly SRC=${TREXIO_ROOT}/src
|
||||||
|
readonly INCLUDIR=${TREXIO_ROOT}/include
|
||||||
|
readonly TOOLS=${TREXIO_ROOT}/tools
|
||||||
|
readonly PYDIR=${TREXIO_ROOT}/python
|
||||||
|
|
||||||
|
# We want the script to crash on the 1st error:
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Create src directory in the python folder if not yet done
|
||||||
|
mkdir -p ${PYDIR}/src
|
||||||
|
|
||||||
|
# Copy all the source code and header files in the corresponding python directory
|
||||||
|
cp ${SRC}/*.py ${PYDIR}
|
||||||
|
cp ${SRC}/*.c ${PYDIR}/src
|
||||||
|
cp ${SRC}/*.h ${PYDIR}/src
|
||||||
|
cp ${INCLUDIR}/trexio.h ${PYDIR}/src
|
||||||
|
|
||||||
|
# Copy additional info
|
||||||
|
cp ${TREXIO_ROOT}/AUTHORS ${TREXIO_ROOT}/LICENSE ${TREXIO_ROOT}/README.md ${PYDIR}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user