|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Run this script to build the ITK Python wheel packages for macOS. |
| 4 | +# |
| 5 | +# Versions can be restricted by passing them in as arguments to the script |
| 6 | +# For example, |
| 7 | +# |
| 8 | +# scripts/macpython-build-wheels.sh 3.9 |
| 9 | +# |
| 10 | +# Shared libraries can be included in the wheel by exporting them to DYLD_LIBRARY_PATH before |
| 11 | +# running this script. |
| 12 | +# |
| 13 | +# For example, |
| 14 | +# |
| 15 | +# export DYLD_LIBRARY_PATH="/path/to/libs" |
| 16 | +# scripts/macpython-build-module-wheels.sh 3.9 |
| 17 | +# |
| 18 | + |
| 19 | +# ----------------------------------------------------------------------- |
| 20 | +# These variables are set in common script: |
| 21 | +# |
| 22 | +MACPYTHON_PY_PREFIX="" |
| 23 | +PYBINARIES="" |
| 24 | +SCRIPT_DIR="" |
| 25 | + |
| 26 | +script_dir=$(cd $(dirname $0) || exit 1; pwd) |
| 27 | +source "${script_dir}/macpython-build-common.sh" |
| 28 | + |
| 29 | +# ----------------------------------------------------------------------- |
| 30 | +# Remove previous virtualenv's |
| 31 | +rm -rf ${SCRIPT_DIR}/../venvs |
| 32 | +# Create virtualenv's |
| 33 | +VENVS=() |
| 34 | +mkdir -p ${SCRIPT_DIR}/../venvs |
| 35 | +for PYBIN in "${PYBINARIES[@]}"; do |
| 36 | + if [[ $(basename $PYBIN) = "Current" ]]; then |
| 37 | + continue |
| 38 | + fi |
| 39 | + py_mm=$(basename ${PYBIN}) |
| 40 | + VENV=${SCRIPT_DIR}/../venvs/${py_mm} |
| 41 | + VIRTUALENV_EXECUTABLE="${PYBIN}/bin/python3 -m venv" |
| 42 | + ${VIRTUALENV_EXECUTABLE} ${VENV} |
| 43 | + VENVS+=(${VENV}) |
| 44 | +done |
| 45 | + |
| 46 | +VENV="${VENVS[0]}" |
| 47 | +Python3_EXECUTABLE=${VENV}/bin/python3 |
| 48 | +${Python3_EXECUTABLE} -m pip install --no-cache delocate |
| 49 | +DELOCATE_LISTDEPS=${VENV}/bin/delocate-listdeps |
| 50 | +DELOCATE_WHEEL=${VENV}/bin/delocate-wheel |
| 51 | +DELOCATE_PATCH=${VENV}/bin/delocate-patch |
| 52 | + |
| 53 | +build_type="Release" |
| 54 | + |
| 55 | +if [[ $(arch) == "arm64" ]]; then |
| 56 | + osx_target="11.0" |
| 57 | + osx_arch="arm64" |
| 58 | + use_tbb="OFF" |
| 59 | +else |
| 60 | + osx_target="10.9" |
| 61 | + osx_arch="x86_64" |
| 62 | + use_tbb="OFF" |
| 63 | +fi |
| 64 | + |
| 65 | +for wheel in dist/*.whl; do |
| 66 | + echo "Delocating $wheel" |
| 67 | + #if [[ $wheel = *itk_core* ]]; then |
| 68 | + ${DELOCATE_LISTDEPS} $wheel # lists library dependencies |
| 69 | + ${DELOCATE_WHEEL} $wheel # copies library dependencies into wheel |
| 70 | + #else |
| 71 | + #${DELOCATE_PATCH} $wheel ${SCRIPT_DIR}/delocate.package.apply.patch # workaround for delocate's need for a package |
| 72 | + #${DELOCATE_LISTDEPS} $wheel # lists library dependencies |
| 73 | + #${DELOCATE_WHEEL} $wheel # copies library dependencies into wheel |
| 74 | + #${DELOCATE_PATCH} $wheel ${SCRIPT_DIR}/delocate.package.revert.patch # workaround for delocate's need for a package |
| 75 | + #fi |
| 76 | +done |
| 77 | + |
| 78 | +# Install packages and test |
| 79 | +# numpy wheel not currently available for the M1 |
| 80 | +# https://github.com/numpy/numpy/issues/17807 |
| 81 | +if [[ $(arch) != "arm64" ]]; then |
| 82 | + for VENV in "${VENVS[@]}"; do |
| 83 | + ${VENV}/bin/pip install numpy |
| 84 | + ${VENV}/bin/pip install itk --no-cache-dir --no-index -f ${SCRIPT_DIR}/../dist |
| 85 | + (cd $HOME && ${VENV}/bin/python -c 'import itk;') |
| 86 | + (cd $HOME && ${VENV}/bin/python -c 'import itk; image = itk.Image[itk.UC, 2].New()') |
| 87 | + (cd $HOME && ${VENV}/bin/python -c 'import itkConfig; itkConfig.LazyLoading = False; import itk;') |
| 88 | + (cd $HOME && ${VENV}/bin/python ${SCRIPT_DIR}/../docs/code/test.py ) |
| 89 | + done |
| 90 | +fi |
0 commit comments