Skip to content

Instantly share code, notes, and snippets.

@fsantini
Last active December 11, 2023 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fsantini/25074839adf5eb089c62d3a00e30e299 to your computer and use it in GitHub Desktop.
Save fsantini/25074839adf5eb089c62d3a00e30e299 to your computer and use it in GitHub Desktop.
Script to generate SimpleElastix wheels for pip under linux, using the official manylinux image

Important notice

This is an unofficial build of SimpleITK where SimpleElastix is enabled. The codebase is unmodified except for the output package name.

This release is provided by Francesco Santini francesco.santini@unibas.ch and is unaffiliated with SimpleITK, The Insight Software Consortium, or NumFOCUS.

Please find the official release at https://github.com/SimpleITK/SimpleITK.

The build script for linux can be found at https://gist.github.com/fsantini/25074839adf5eb089c62d3a00e30e299

Original copyright notice

The SimpleITK project is part of the Insight Software Consortium(ISC) a non-profit educational consortium dedicated to promoting and maintaining open-source, freely available software for bio-medical image analysis. The copyright is held by NumFOCUS. The SimpleITK software is distributed under the Apache License 2.0.

#!/bin/bash
# run this with
# docker run --rm -e PYTHON_TARGET=cp310-cp310 -v /home/user/local_dir:/io quay.io/pypa/manylinux2014_x86_64 /io/make_selx.sh
set -e # stop on errors
IO_DIR=/io/wheels
BASE_DIR=${BASE_DIR:-/src}
PLAT=$AUDITWHEEL_PLAT
PYTHON_TARGET=${PYTHON_TARGET:-cp310-cp310}
MODULE_NAME=${MODULE_NAME:-SimpleITK-SimpleElastix}
MAKE_THREADS=${MAKE_THREADS:-$(cat /proc/cpuinfo | grep -c processor)}
PYTHON_BIN=/opt/python/$PYTHON_TARGET/bin
PYTHON_EXE=$PYTHON_BIN/python
INCLUDES=(/opt/python/$PYTHON_TARGET/include/*) # all subdirs
PYTHON_INCLUDE=${INCLUDES[0]} # get the appropriate include directory
echo ======== Using Python: $PYTHON_EXE ============
$PYTHON_EXE -V
echo ======== Platform: $PLAT ======================
echo ======== Make threads: $MAKE_THREADS ==========
mkdir -p "$BASE_DIR"
cd $BASE_DIR
git clone https://github.com/SimpleITK/SimpleITK.git
cd SimpleITK
mkdir build
cd build
cmake ../SuperBuild
cmake -DBUILD_EXAMPLES:BOOL=OFF \
-DBUILD_TESTING:BOOL=OFF \
-DWRAP_CSHARP:BOOL=OFF \
-DWRAP_JAVA:BOOL=OFF \
-DWRAP_LUA:BOOL=OFF \
-DWRAP_R:BOOL=OFF \
-DWRAP_RUBY:BOOL=OFF \
-DWRAP_TCL:BOOL=OFF \
-DWRAP_PYTHON:BOOL=ON \
-DPython_EXECUTABLE:STRING=$PYTHON_EXE \
-DPython_INCLUDE_DIR:STRING=$PYTHON_INCLUDE \
-DSimpleITK_USE_ELASTIX=ON .
make -j$MAKE_THREADS
echo ====== Successfully compiled SimpleElastix ======
# copy the setup.py script
#cp SimpleITK-build/Wrapping/Python/Packaging/setup.py SimpleITK-build/Wrapping/Python/
cd SimpleITK-build/Wrapping/Python/
#sed -i.bak -e "s/sitkHASH\s*=\s*[\"'][a-zA-Z0-9]*[\"']/sitkHASH = None/" -e "s/name\s*=\s*[\"']SimpleITK[\"']/name='$MODULE_NAME'/" setup.py
sed -i.bak -e "s/version\s*=\s*__version__/version=__version__.split('+')[0]/" -e "s/name\s*=\s*[\"']SimpleITK[\"']/name='$MODULE_NAME'/" -e "s/with open('Readme\.md'/with open('\/io\/Readme_unofficial.md'/" setup.py
$PYTHON_EXE setup.py bdist_wheel
cd dist
auditwheel repair --plat $PLAT *.whl
mkdir -p "$IO_DIR"
cp wheelhouse/*.whl "$IO_DIR"
echo ====== Successfully built wheel ======
ls $IO_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment