2021-09-13 14:54:00 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-09-09 17:35:24 +02:00
|
|
|
set -x
|
2021-12-27 16:26:17 +01:00
|
|
|
set -e
|
2021-09-09 17:35:24 +02:00
|
|
|
|
|
|
|
export H5_LDFLAGS=-L/usr/local/lib
|
|
|
|
export H5_CFLAGS=-I/usr/local/include
|
|
|
|
|
2022-01-07 10:25:09 +01:00
|
|
|
readonly ROOTDIR=${PWD}
|
|
|
|
|
|
|
|
# create the wheelhouse directory
|
|
|
|
mkdir -p ${ROOTDIR}/wheelhouse
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# build wheel directly from developer-provided .tar.gz of TREXIO (generated with `python setup.py sdist`)
|
|
|
|
# note: trexio-VERSION.tar.gz has to be in the root directory of the host machine and provided as an argument to this script
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-13 14:54:00 +02:00
|
|
|
# process input: first argument is the name of the .tar.gz with the source code of the Python API
|
|
|
|
if [[ -z "$1" ]]; then
|
|
|
|
echo "Please specify the name of the TREXIO source code distribution (with .tar.gz suffix)"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# derive TREXIO version from the file name
|
2021-09-13 14:54:00 +02:00
|
|
|
TREXIO_SOURCE=${1}
|
|
|
|
# remove prefix that ends with "-"
|
|
|
|
tmp=${TREXIO_SOURCE#*-}
|
|
|
|
# remove suffix that ends with ".tar.gz"
|
|
|
|
TR_VERSION=${tmp%.tar.gz*}
|
2021-09-14 17:28:05 +02:00
|
|
|
# print the computed version
|
2021-09-13 14:54:00 +02:00
|
|
|
echo "TREXIO VERSION:" ${TR_VERSION}
|
|
|
|
|
2021-09-09 17:35:24 +02:00
|
|
|
# unzip and enter the folder with TREXIO Python API
|
2022-01-07 10:25:09 +01:00
|
|
|
gzip -cd ${TREXIO_SOURCE} | tar xvf -
|
2021-09-13 14:54:00 +02:00
|
|
|
cd trexio-${TR_VERSION}
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# the function below build manylinux wheels based on the provided version of python (e.g. build_wheel_for_py 36)
|
2021-12-27 16:26:17 +01:00
|
|
|
function build_wheel_for_py()
|
2021-09-14 17:28:05 +02:00
|
|
|
{
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
if [[ -z "$1" ]]; then
|
|
|
|
echo "Empty string provided instead of the Python version"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# derive PYVERSION from the input argument
|
|
|
|
PYVERSION=${1}
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2022-01-07 10:25:09 +01:00
|
|
|
# derive manylinux glibc tag from the PLAT env variable provided to docker run
|
|
|
|
# this is needed to avoid building wheel for 2010_x86_64 with CPython 3.10
|
|
|
|
# because NumPy does not have wheels for it
|
|
|
|
MANYLINUX_TAG=${PLAT:9:4}
|
|
|
|
if [[ ${PYVERSION} -eq 310 ]] && [[ ${MANYLINUX_TAG} -eq 2010 ]]; then
|
|
|
|
echo "Skip build of the wheel for CPython 3.10 on manylinux2010_x86_64"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# python versions <= 3.7 required additional "m" in the platform tag, e.g. cp37-cp37m
|
|
|
|
if [[ ${PYVERSION} -eq 36 ]] || [[ ${PYVERSION} -eq 37 ]]; then
|
|
|
|
PYM="m"
|
|
|
|
else
|
|
|
|
PYM=""
|
|
|
|
fi
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
CPYTHON="cp${PYVERSION}-cp${PYVERSION}${PYM}"
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# create and activate a virtual environment based on CPython version ${PYVERSION}
|
|
|
|
/opt/python/${CPYTHON}/bin/python3 -m venv --clear trexio-manylinux-py${PYVERSION}
|
2021-12-27 16:26:17 +01:00
|
|
|
source trexio-manylinux-py${PYVERSION}/bin/activate
|
2021-09-14 17:28:05 +02:00
|
|
|
python3 --version
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# upgrade pip, otherwise it complains that manylinux wheel is "...not supported wheel on this platform"
|
2021-12-27 16:26:17 +01:00
|
|
|
pip install --upgrade pip
|
2021-09-14 17:28:05 +02:00
|
|
|
# install dependencies needed to build manylinux wheel
|
2022-01-07 18:47:23 +01:00
|
|
|
pip install --upgrade setuptools build
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# produce conventional (non-manylinux) wheel
|
2022-01-07 18:47:23 +01:00
|
|
|
python3 -m build --wheel --outdir dist/
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# use auditwheel from PyPA to repair all wheels and make them manylinux-compatible
|
|
|
|
auditwheel repair dist/trexio-${TR_VERSION}-${CPYTHON}-*.whl
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# install the produced manylinux wheel in the virtual environment
|
|
|
|
python3 -m pip install wheelhouse/trexio-${TR_VERSION}-${CPYTHON}-manylinux*.whl
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2022-06-01 17:52:52 +02:00
|
|
|
# install pytest for testing
|
|
|
|
pip install pytest
|
2021-09-14 17:28:05 +02:00
|
|
|
# run test script
|
2022-06-01 17:52:52 +02:00
|
|
|
pytest -v test/test_api.py
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# cleaning
|
2022-06-01 17:52:52 +02:00
|
|
|
rm -rf -- dist/ build/ trexio.egg-info/
|
|
|
|
rm -- test_file_py.h5 unsafe_test_file_py.h5
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# deactivate the current environment
|
|
|
|
deactivate
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2021-09-14 17:28:05 +02:00
|
|
|
# remove the virtual environment
|
|
|
|
rm -rf -- trexio-manylinux-py${PYVERSION}
|
2021-09-09 17:35:24 +02:00
|
|
|
|
2022-01-07 10:25:09 +01:00
|
|
|
# move the wheelhouse directory to the ROOTDIR
|
|
|
|
mv wheelhouse/trexio-${TR_VERSION}-${CPYTHON}-manylinux*.whl ${ROOTDIR}/wheelhouse/
|
2021-09-14 17:28:05 +02:00
|
|
|
}
|
2021-09-09 17:35:24 +02:00
|
|
|
|
|
|
|
|
2021-12-27 16:26:17 +01:00
|
|
|
# build wheels for all versions of CPython in this container
|
|
|
|
for CPYVERSION in 36 37 38 39 310
|
2021-09-14 17:28:05 +02:00
|
|
|
do
|
|
|
|
build_wheel_for_py ${CPYVERSION}
|
|
|
|
done
|