From 816fe729499a5ebc92a3d41dfe16c83ca41fd914 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 14 Sep 2021 17:28:05 +0200 Subject: [PATCH] more flexible build_manylinux_wheels bash script --- .../build_manylinux_wheels_py_36_37_38_39.sh | 193 +++++------------- 1 file changed, 50 insertions(+), 143 deletions(-) diff --git a/docker/build_manylinux_wheels_py_36_37_38_39.sh b/docker/build_manylinux_wheels_py_36_37_38_39.sh index 9c6390b..d8dd280 100755 --- a/docker/build_manylinux_wheels_py_36_37_38_39.sh +++ b/docker/build_manylinux_wheels_py_36_37_38_39.sh @@ -6,38 +6,9 @@ set -e export H5_LDFLAGS=-L/usr/local/lib export H5_CFLAGS=-I/usr/local/include -# install emacs for Debian -#apt-get update -#apt install software-properties-common -y -#apt-get install wget -y - -#wget -q http://emacs.ganneff.de/apt.key -O- | apt-key add - -#add-apt-repository "deb http://emacs.ganneff.de/ stretch main" -#apt-get update -#apt-get install emacs-snapshot -y -#update-alternatives --config emacsclient - -# =============================== - -# install TREXIO in the container from the GitHub repo clone - -#apt-get install git -y - -#git clone https://github.com/TREX-CoE/trexio.git -#cd trexio -#git checkout swig-python - -#./autogen.sh -#TREXIO_DEVEL=1 ./configure --enable-silent-rules -#make -#make check - -# =============================== - -# alternatively: 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 +# 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 # process input: first argument is the name of the .tar.gz with the source code of the Python API if [[ -z "$1" ]]; then @@ -45,144 +16,80 @@ if [[ -z "$1" ]]; then exit 1 fi +# derive TREXIO version from the file name TREXIO_SOURCE=${1} - # remove prefix that ends with "-" tmp=${TREXIO_SOURCE#*-} # remove suffix that ends with ".tar.gz" TR_VERSION=${tmp%.tar.gz*} - +# print the computed version echo "TREXIO VERSION:" ${TR_VERSION} # unzip and enter the folder with TREXIO Python API gzip -cd /tmp/trexio-${TR_VERSION}.tar.gz | tar xvf - cd trexio-${TR_VERSION} -# create and activate a virtual environment based on CPython version 3.6 -/opt/python/cp36-cp36m/bin/python3 -m venv --clear trexio-manylinux-py36 -source trexio-manylinux-py36/bin/activate -python3 --version +# the function below build manylinux wheels based on the provided version of python (e.g. build_wheel_for_py 36) +function build_wheel_for_py() +{ -# upgrade pip, otherwise it complains that manylinux wheel is "...not supported wheel on this platform" -pip install --upgrade pip -# install dependencies needed to build manylinux wheel -pip install --upgrade setuptools wheel auditwheel numpy + if [[ -z "$1" ]]; then + echo "Empty string provided instead of the Python version" + exit 1 + fi -# set an environment variable needed to locate numpy header files -source tools/set_NUMPY_INCLUDEDIR.sh + # derive PYVERSION from the input argument + PYVERSION=${1} -# produce conventional (non-manylinux) wheel -python3 setup.py bdist_wheel + # 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 -# use auditwheel from PyPA to repair all wheels and make them manylinux-compatible -auditwheel repair dist/trexio-${TR_VERSION}-cp36-cp36m-*.whl + CPYTHON="cp${PYVERSION}-cp${PYVERSION}${PYM}" -# install the produced manylinux wheel in the virtual environment -python3 -m pip install wheelhouse/trexio-${TR_VERSION}-cp36-cp36m-manylinux*.whl + # create and activate a virtual environment based on CPython version ${PYVERSION} + /opt/python/${CPYTHON}/bin/python3 -m venv --clear trexio-manylinux-py${PYVERSION} + source trexio-manylinux-py${PYVERSION}/bin/activate + python3 --version -# run test script -cd test && python3 test_api.py && cd .. + # upgrade pip, otherwise it complains that manylinux wheel is "...not supported wheel on this platform" + pip install --upgrade pip + # install dependencies needed to build manylinux wheel + pip install --upgrade setuptools wheel auditwheel numpy -# cleaning -rm -rf -- dist/ build/ trexio.egg-info/ + # set an environment variable needed to locate numpy header files + source tools/set_NUMPY_INCLUDEDIR.sh -# deactivate the current environment -deactivate + # produce conventional (non-manylinux) wheel + python3 setup.py bdist_wheel -# create and activate a virtual environment based on CPython version 3.7 -/opt/python/cp37-cp37m/bin/python3 -m venv --clear trexio-manylinux-py37 -source trexio-manylinux-py37/bin/activate -python3 --version + # use auditwheel from PyPA to repair all wheels and make them manylinux-compatible + auditwheel repair dist/trexio-${TR_VERSION}-${CPYTHON}-*.whl -# upgrade pip, otherwise it complains that manylinux wheel is "...not supported wheel on this platform" -pip install --upgrade pip -# install dependencies needed to build manylinux wheel -pip install --upgrade setuptools wheel auditwheel numpy + # install the produced manylinux wheel in the virtual environment + python3 -m pip install wheelhouse/trexio-${TR_VERSION}-${CPYTHON}-manylinux*.whl -# set an environment variable needed to locate numpy header files -source tools/set_NUMPY_INCLUDEDIR.sh + # run test script + cd test && python3 test_api.py && cd .. -# produce conventional (non-manylinux) wheel -python3 setup.py bdist_wheel + # cleaning + rm -rf -- dist/ build/ trexio.egg-info/ -# use auditwheel from PyPA to repair all wheels and make them manylinux-compatible -auditwheel repair dist/trexio-${TR_VERSION}-cp37-cp37m-*.whl + # deactivate the current environment + deactivate -# install the produced manylinux wheel in the virtual environment -python3 -m pip install wheelhouse/trexio-${TR_VERSION}-cp37-cp37m-manylinux*.whl + # remove the virtual environment + rm -rf -- trexio-manylinux-py${PYVERSION} -# run test script -cd test && python3 test_api.py && cd .. +} -# cleaning -rm -rf -- dist/ build/ trexio.egg-info/ -# deactivate the current environment -deactivate - -# create and activate a virtual environment based on CPython version 3.8 -# NOTE: starting from CPython 3.8 there is no need to add m in the abi-tag, e.g. use cp38-cp38 instead of cp38-cp38m -/opt/python/cp38-cp38/bin/python3 -m venv --clear trexio-manylinux-py38 -source trexio-manylinux-py38/bin/activate -python3 --version - -# upgrade pip, otherwise it complains that manylinux wheel is "...not supported wheel on this platform" -pip install --upgrade pip -# install dependencies needed to build manylinux wheel -pip3 install --upgrade setuptools wheel auditwheel numpy - -# set an environment variable needed to locate numpy header files -source tools/set_NUMPY_INCLUDEDIR.sh - -# produce conventional (non-manylinux) wheel -python3 setup.py bdist_wheel - -# use auditwheel from PyPA to repair all wheels and make them manylinux-compatible -auditwheel repair dist/trexio-${TR_VERSION}-cp38-cp38-*.whl - -# install the produced manylinux wheel in the virtual environment -python3 -m pip install wheelhouse/trexio-${TR_VERSION}-cp38-cp38-manylinux*.whl - -# run test script -cd test && python3 test_api.py && cd .. - -# cleaning -rm -rf -- dist/ build/ trexio.egg-info/ - -# deactivate the current environment -deactivate - -# create and activate a virtual environment based on CPython version 3.8 -/opt/python/cp39-cp39/bin/python3 -m venv --clear trexio-manylinux-py39 -source trexio-manylinux-py39/bin/activate -python3 --version - -# upgrade pip, otherwise it complains that manylinux wheel is "...not supported wheel on this platform" -pip install --upgrade pip -# install dependencies needed to build manylinux wheel -pip3 install --upgrade setuptools wheel auditwheel numpy - -# produce conventional (non-manylinux) wheel -python3 setup.py bdist_wheel - -# use auditwheel from PyPA to repair all wheels and make them manylinux-compatible -auditwheel repair dist/trexio-${TR_VERSION}-cp39-cp39-*.whl - -# install the produced manylinux wheel in the virtual environment -python3 -m pip install wheelhouse/trexio-${TR_VERSION}-cp39-cp39-manylinux*.whl - -# run test script -cd test && python3 test_api.py && cd .. - -# cleaning -rm -rf -- dist/ build/ trexio.egg-info/ - -# deactivate the current environment -deactivate - -# remove all virtual environments used to produce the wheels -rm -rf -- trexio-manylinux-py39 \ - trexio-manylinux-py38 \ - trexio-manylinux-py37 \ - trexio-manylinux-py36 +# build wheels for all versions of CPython in this container +for CPYVERSION in 36 37 38 39 +do + build_wheel_for_py ${CPYVERSION} +done