├── .github ├── dependabot.yml └── workflows │ └── main.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── MANIFEST.in ├── README.md ├── pyproject.toml ├── scripts ├── dockcross-manylinux-build-wheels.sh └── internal │ ├── manylinux-build-wheels.sh │ └── manylinux-libpython-not-needed-symbols-exported-by-interpreter └── setup.py /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Python Test and Package 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | tags: 8 | - 'v*' 9 | pull_request: 10 | branches: 11 | - main 12 | 13 | jobs: 14 | package: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v4 18 | with: 19 | fetch-depth: 1 20 | submodules: true 21 | - name: Set up Python 3.11 22 | uses: actions/setup-python@v4 23 | with: 24 | python-version: 3.11 25 | - name: Install dependencies 26 | run: | 27 | python -m pip install --upgrade pip 28 | python -m pip install build twine 29 | - name: build package 30 | run: | 31 | python -m build --sdist . 32 | - name: twine test 33 | run: | 34 | python -m twine check dist/* 35 | - name: Upload package 36 | uses: actions/upload-artifact@v4 37 | with: 38 | name: python-packages 39 | path: dist 40 | - name: List 41 | run: | 42 | ls -la dist 43 | 44 | 45 | build: 46 | needs: package 47 | strategy: 48 | matrix: 49 | os: [ubuntu-latest, macos-latest] 50 | python-version: ['3.9', '3.13'] 51 | runs-on: ${{ matrix.os }} 52 | steps: 53 | - uses: actions/download-artifact@v4.3.0 54 | id: download 55 | with: 56 | name: python-packages 57 | - name: Set up Python ${{ matrix.python-version }} 58 | uses: actions/setup-python@v5 59 | with: 60 | python-version: ${{ matrix.python-version }} 61 | - name: Install tools 62 | run: | 63 | python -m pip install --upgrade pip 64 | - name: Build and Install SimpleITK Package 65 | run: | 66 | python -m pip install ${{steps.download.outputs.download-path}}/simpleitk-*.tar.gz 67 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # This project 2 | scripts/manylinux-libpython-not-needed-symbols-exported-by-interpreter 3 | skbuild 4 | standalone-build 5 | standalone-x86-build 6 | standalone-x64-build 7 | 8 | # Python 9 | *.py[cod] 10 | 11 | # C extensions 12 | *.so 13 | 14 | # Packages 15 | *.egg 16 | *.eggs 17 | *.egg-info 18 | dist 19 | build 20 | _skbuild 21 | eggs 22 | parts 23 | bin 24 | var 25 | sdist 26 | develop-eggs 27 | .installed.cfg 28 | lib 29 | lib64 30 | MANIFEST 31 | 32 | # Installer logs 33 | pip-log.txt 34 | 35 | # Unit test / coverage reports 36 | .coverage 37 | .tox 38 | coverage.xml 39 | nosetests.xml 40 | htmlcov 41 | 42 | # Translations 43 | *.mo 44 | 45 | # Mr Developer 46 | .mr.developer.cfg 47 | .project 48 | .pydevproject 49 | 50 | # Complexity 51 | output/*.html 52 | output/*/index.html 53 | 54 | # Sphinx 55 | docs/_build 56 | 57 | # IDE junk 58 | .idea/* 59 | *.swp 60 | 61 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "SimpleITK"] 2 | path = SimpleITK 3 | url = https://github.com/SimpleITK/SimpleITK.git 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | cmake_minimum_required(VERSION 3.26) 3 | 4 | project(SimpleITKPythonPackage NONE) 5 | 6 | if(NOT DEFINED SimpleITKPythonPackage_SUPERBUILD) 7 | set(SimpleITKPythonPackage_SUPERBUILD 1) 8 | endif() 9 | 10 | # Set a default build type if none was specified 11 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 12 | message(STATUS "Setting build type to 'Release' as none was specified.") 13 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) 14 | mark_as_advanced(CMAKE_BUILD_TYPE) 15 | # Set the possible values of build type for cmake-gui 16 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" 17 | "MinSizeRel" "RelWithDebInfo") 18 | endif() 19 | 20 | if(NOT DEFINED SimpleITK_SOURCE_DIR) 21 | set(SimpleITK_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/SimpleITK") 22 | endif() 23 | 24 | if(SimpleITKPythonPackage_SUPERBUILD) 25 | 26 | set(ep_common_cmake_cache_args) 27 | if(NOT CMAKE_CONFIGURATION_TYPES) 28 | list(APPEND ep_common_cmake_cache_args 29 | -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} 30 | ) 31 | endif() 32 | 33 | #----------------------------------------------------------------------------- 34 | # Options 35 | option ( SimpleITK_PYTHON_THREADS "Enable threaded python usage by unlocking the GIL." ON ) 36 | mark_as_advanced( SimpleITK_PYTHON_THREADS ) 37 | 38 | # 39 | # When building different "flavor" of SimpleITK python packages on a given platform, 40 | # explicitly setting the following options allow to speed up package generation by 41 | # re-using existing resources. 42 | # 43 | # SimpleITK_SOURCE_DIR: Path to an existing source directory 44 | # 45 | # SWIG_EXECUTABLE: Path to an existing executable 46 | # 47 | # SimpleITK_DIR: Path to an existing SimpleITK build or install directory 48 | # 49 | 50 | option ( SimpleITKPythonPackage_BUILD_PYTHON "Build SimpleITK python module" ON ) 51 | mark_as_advanced( SimpleITKPythonPackage_BUILD_PYTHON ) 52 | 53 | # compile with multiple processors 54 | include(ProcessorCount) 55 | ProcessorCount(NPROC) 56 | if (NOT NPROC EQUAL 0) 57 | set( ENV{MAKEFLAGS} "-j${NPROC}" ) 58 | endif() 59 | 60 | #----------------------------------------------------------------------------- 61 | include(ExternalProject) 62 | 63 | # Add an empty external project 64 | function(sitk_ExternalProject_Add_Empty proj depends) 65 | set(depends_args) 66 | if(NOT depends STREQUAL "") 67 | set(depends_args DEPENDS ${depends}) 68 | endif() 69 | ExternalProject_add(${proj} 70 | SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj} 71 | DOWNLOAD_COMMAND "" 72 | UPDATE_COMMAND "" 73 | CONFIGURE_COMMAND "" 74 | BUILD_COMMAND "" 75 | BUILD_IN_SOURCE 1 76 | BUILD_ALWAYS 1 77 | INSTALL_COMMAND "" 78 | ${depends_args} 79 | ) 80 | endfunction() 81 | 82 | 83 | #----------------------------------------------------------------------------- 84 | # A separate project is used to download SimpleITK, so that the SuperBuild 85 | # subdirectory can be use for SimpleITK's SuperBuild to build the 86 | # required Lua, GTest etc. 87 | 88 | # Sanity checks 89 | if(DEFINED SimpleITK_SOURCE_DIR AND NOT EXISTS ${SimpleITK_SOURCE_DIR}) 90 | message(FATAL_ERROR "SimpleITK_SOURCE_DIR variable is defined but corresponds to nonexistent directory: \"${SimpleITK_SOURCE_DIR}\"") 91 | endif() 92 | 93 | message(STATUS "SuperBuild - SimpleITK_SOURCE_DIR: ${SimpleITK_SOURCE_DIR}") 94 | 95 | #----------------------------------------------------------------------------- 96 | # SimpleITK "Core" libraries: This is the SimpleITK Superbuild project 97 | # that build all the tools needed (GTest, PCRE, Swig, Lua & GTest) and 98 | # then SimpleITK "core" libraries. 99 | 100 | message(STATUS "SuperBuild - SimpleITK-superbuild") 101 | 102 | # Sanity checks 103 | if(DEFINED SimpleITK_DIR AND NOT EXISTS ${SimpleITK_DIR}) 104 | message(FATAL_ERROR "SimpleITK_DIR variable is defined but corresponds to nonexistent directory") 105 | endif() 106 | if(DEFINED SWIG_EXECUTABLE AND NOT EXISTS ${SWIG_EXECUTABLE}) 107 | message(FATAL_ERROR "SWIG_EXECUTABLE variable is defined but corresponds to nonexistent file") 108 | endif() 109 | 110 | if(NOT DEFINED SimpleITK_DIR AND NOT DEFINED SWIG_EXECUTABLE) 111 | 112 | set(SimpleITK_SUPERBUILD_DIR ${CMAKE_BINARY_DIR}/sitk-sb) 113 | 114 | ExternalProject_add(SimpleITK-superbuild 115 | SOURCE_DIR ${SimpleITK_SOURCE_DIR}/SuperBuild 116 | BINARY_DIR ${SimpleITK_SUPERBUILD_DIR} 117 | DOWNLOAD_COMMAND "" 118 | UPDATE_COMMAND "" 119 | CMAKE_CACHE_ARGS 120 | ${ep_common_cmake_cache_args} 121 | -DBUILD_EXAMPLES:BOOL=OFF 122 | -DBUILD_TESTING:BOOL=OFF 123 | -DBUILD_DOXYGEN:BOOL=OFF 124 | -DWRAP_DEFAULT:BOOL=OFF 125 | -DSimpleITK_INSTALL_DOC_DIR:STRING=SimpleITK 126 | -DSimpleITK_BUILD_STRIP:BOOL=ON 127 | -DSimpleITK_BUILD_DISTRIBUTE:BOOL=ON 128 | -DSimpleITK_GIT_PROTOCOL:STRING=https 129 | -DSKBUILD:BOOL=${SKBUILD} 130 | USES_TERMINAL_CONFIGURE 1 131 | USES_TERMINAL_BUILD 1 132 | INSTALL_COMMAND "" 133 | ) 134 | 135 | set(SimpleITK_DIR ${SimpleITK_SUPERBUILD_DIR}/SimpleITK-build) 136 | set(ITK_DIR ${SimpleITK_SUPERBUILD_DIR}/ITK-prefix/lib/cmake/ITK) 137 | if(WIN32) 138 | set(SWIG_EXECUTABLE ${SimpleITK_SUPERBUILD_DIR}/swigwin/swig.exe) 139 | else() 140 | set(SWIG_EXECUTABLE ${SimpleITK_SUPERBUILD_DIR}/Swig/bin/swig) 141 | endif() 142 | else() 143 | 144 | sitk_ExternalProject_Add_Empty( 145 | SimpleITK-superbuild 146 | ) 147 | 148 | endif() 149 | 150 | message(STATUS "SuperBuild - SimpleITK_DIR: ${SimpleITK_DIR}") 151 | message(STATUS "SuperBuild - ITK_DIR: ${ITK_DIR}") 152 | message(STATUS "SuperBuild - SWIG_EXECUTABLE: ${SWIG_EXECUTABLE}") 153 | 154 | 155 | #----------------------------------------------------------------------------- 156 | if(NOT SimpleITKPythonPackage_BUILD_PYTHON) 157 | return() 158 | endif() 159 | 160 | 161 | #----------------------------------------------------------------------------- 162 | # Search for python interpreter and libraries 163 | 164 | message(STATUS "SuperBuild - Searching for python") 165 | 166 | if ( PYTHON_VERSION_STRING VERSION_GREATER_EQUAL "3.11.0") 167 | 168 | set(_SimpleITK_PYTHON_USE_LIMITED_API_DEFAULT ON) 169 | else () 170 | set(_SimpleITK_PYTHON_USE_LIMITED_API_DEFAULT OFF) 171 | endif() 172 | option( SimpleITK_PYTHON_USE_LIMITED_API "Use Python limited API, for minor version compatibility." ${_SimpleITK_PYTHON_USE_LIMITED_API_DEFAULT} ) 173 | 174 | # Sanity checks 175 | if(DEFINED PYTHON_INCLUDE_DIR AND NOT EXISTS ${PYTHON_INCLUDE_DIR}) 176 | message(FATAL_ERROR "PYTHON_INCLUDE_DIR variable is defined but corresponds to nonexistent directory") 177 | endif() 178 | if(DEFINED PYTHON_LIBRARY AND NOT EXISTS ${PYTHON_LIBRARY}) 179 | message(FATAL_ERROR "PYTHON_LIBRARY variable is defined but corresponds to nonexistent file") 180 | endif() 181 | if(DEFINED PYTHON_EXECUTABLE AND NOT EXISTS ${PYTHON_EXECUTABLE}) 182 | message(FATAL_ERROR "PYTHON_EXECUTABLE variable is defined but corresponds to nonexistent file") 183 | endif() 184 | 185 | if(NOT DEFINED PYTHON_INCLUDE_DIR 186 | OR NOT DEFINED PYTHON_LIBRARY 187 | OR NOT DEFINED PYTHON_EXECUTABLE) 188 | 189 | find_package ( PythonLibs REQUIRED ) 190 | find_package ( PythonInterp REQUIRED ) 191 | 192 | endif() 193 | 194 | message(STATUS "SuperBuild - PYTHON_INCLUDE_DIR: ${PYTHON_INCLUDE_DIR}") 195 | message(STATUS "SuperBuild - PYTHON_LIBRARY: ${PYTHON_LIBRARY}") 196 | message(STATUS "SuperBuild - PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}") 197 | 198 | 199 | #----------------------------------------------------------------------------- 200 | # SimpleITK Python module: This project build only the SimpleITK python 201 | # module. 202 | 203 | message(STATUS "SuperBuild - SimpleITK-python => Requires SimpleITK-superbuild") 204 | 205 | set(SimpleITK_PYTHON_DIR "${CMAKE_BINARY_DIR}/SimpleITK-python") 206 | 207 | ExternalProject_add(SimpleITK-python 208 | SOURCE_DIR ${SimpleITK_SOURCE_DIR}/Wrapping/Python 209 | BINARY_DIR ${SimpleITK_PYTHON_DIR} 210 | DOWNLOAD_COMMAND "" 211 | UPDATE_COMMAND "" 212 | CMAKE_CACHE_ARGS 213 | ${ep_common_cmake_cache_args} 214 | -DPython_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} 215 | -DPython_LIBRARY:PATH=${PYTHON_LIBRARY} 216 | -DPython_EXECUTABLE:PATH=${PYTHON_EXECUTABLE} 217 | -DBUILD_TESTING:BOOL=OFF 218 | -DSimpleITK_PYTHON_THREADS:BOOL=${SimpleITK_PYTHON_THREADS} 219 | -DSimpleITK_PYTHON_USE_LIMITED_API:BOOL=${SimpleITK_PYTHON_USE_LIMITED_API} 220 | -DSimpleITK_DIR:PATH=${SimpleITK_DIR} 221 | -DITK_DIR:PATH=${ITK_DIR} 222 | -DSWIG_EXECUTABLE:PATH=${SWIG_EXECUTABLE} 223 | -DSimpleITK_BUILD_STRIP:BOOL=ON 224 | -DSKBUILD:BOOL=ON 225 | USES_TERMINAL_CONFIGURE 1 226 | USES_TERMINAL_BUILD 1 227 | INSTALL_COMMAND "" 228 | DEPENDS SimpleITK-superbuild 229 | ) 230 | 231 | message(STATUS "SuperBuild - SimpleITK_PYTHON_DIR: ${SimpleITK_PYTHON_DIR}") 232 | 233 | 234 | #----------------------------------------------------------------------------- 235 | # SimpleITKPythonPackage: This project adds install rules for the "Runtime" component 236 | # of both SimpleITK code and python libraries. 237 | 238 | message(STATUS "SuperBuild - ${PROJECT_NAME} => Requires SimpleITK-python") 239 | 240 | ExternalProject_add(${PROJECT_NAME} 241 | SOURCE_DIR ${CMAKE_SOURCE_DIR} 242 | BINARY_DIR ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-build 243 | DOWNLOAD_COMMAND "" 244 | UPDATE_COMMAND "" 245 | CMAKE_CACHE_ARGS 246 | ${ep_common_cmake_cache_args} 247 | -DSimpleITKPythonPackage_SUPERBUILD:BOOL=0 248 | -DSimpleITK_DIR:PATH=${SimpleITK_DIR} 249 | -DSimpleITK_PYTHON_DIR:PATH=${SimpleITK_PYTHON_DIR} 250 | -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} 251 | USES_TERMINAL_CONFIGURE 1 252 | INSTALL_COMMAND "" 253 | DEPENDS SimpleITK-python 254 | ) 255 | 256 | install(SCRIPT ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-build/cmake_install.cmake) 257 | 258 | else() 259 | 260 | #----------------------------------------------------------------------------- 261 | # Install SimpleITK Core "Runtime" components 262 | install(CODE " 263 | unset(CMAKE_INSTALL_COMPONENT) 264 | set(COMPONENT \"Runtime\") 265 | include\(\"${SimpleITK_DIR}/cmake_install.cmake\") 266 | unset(CMAKE_INSTALL_COMPONENT) 267 | ") 268 | 269 | # Install SimpleITK Python "Runtime" components 270 | install(CODE " 271 | unset(CMAKE_INSTALL_COMPONENT) 272 | set(COMPONENT \"Runtime\") 273 | include\(\"${SimpleITK_PYTHON_DIR}/cmake_install.cmake\") 274 | unset(CMAKE_INSTALL_COMPONENT) 275 | ") 276 | 277 | endif() 278 | 279 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include CMakeLists.txt 2 | include README.md 3 | include setup.py 4 | include requirements-dev.txt 5 | graft SimpleITK 6 | prune SimpleITK/.ExternalData 7 | global-exclude .git* 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SimpleITKPythonPackage 2 | 3 | This project provides a `setup.py` script that can build, install, and package SimpleITK for Python. [SimpleITK](http://www.simpleitk.org) is a simplified programming layer on top of the [Insight Segmentation and Registration Toolkit](https://itk.org) (ITK). ITK is an open-source, cross-platform system that provides developers with an extensive suite of software tools for image analysis. 4 | 5 | SimpleITK is available for binary downloads from [PyPI](https://pypi.python.org/pypi/SimpleITK) for many common platforms. Also a source distribution is available of this repository which may be used when an appropriate binary [wheel](http://pythonwheels.com) is not available. 6 | 7 | To install SimpleITK: 8 | 9 | ```bash 10 | pip install SimpleITK 11 | ``` 12 | 13 | ## Installing SimpleITK for Python from the Python Packaging Source 14 | 15 | ```bash 16 | pip install --no-binary :all: SimpleITK 17 | ``` 18 | 19 | ### Prerequisites 20 | 21 | The build requirements are specified in the pyproject.toml file via [PEP 518](https://peps.python.org/pep-0518/). The requirements should be automatically downloaded when using a [PEP 517](https://peps.python.org/pep-0517/) compliant build front-end. 22 | 23 | Additionally building *requires*: 24 | * Git 25 | * C++ Compiler - Platform specific requirements are summarized in [scikit-build documentation](http://scikit-build.readthedocs.io). 26 | * Python 27 | * pip >= 9.0.0 28 | 29 | Please ensure that `pip` is up to date. 30 | 31 | ```bash 32 | python -m pip install --upgrade pip 33 | ``` 34 | 35 | ### Compilations and Installation from Github 36 | 37 | SimpleITK can be compiled and install directly from the github repository: 38 | 39 | ```bash 40 | pip install git+https://github.com/SimpleITK/SimpleITKPythonPackage.git -v 41 | ``` 42 | 43 | ### Compilation and Installation from Source Distribution 44 | 45 | Alternatively, SimpleITK for Python can be compiled and installed from the SimpleITKPythonPackage python source distribution. 46 | 47 | ```bash 48 | pip install SimpleITKPythonPackage-1.0.0.tar.gz 49 | ``` 50 | 51 | The source distributions are available from [PyPI](https://pypi.python.org/pypi/SimpleITK). 52 | 53 | ## Automated wheels building with scripts 54 | 55 | Steps required to build wheels on Linux, MacOSX and Windows have been automated. The 56 | following sections outline how to use the associated scripts. 57 | 58 | ### Linux 59 | 60 | On any linux distribution with `docker` and `bash` installed, running the script 61 | `dockcross-manylinux-build-wheels.sh` will create 32 and 64-bit wheels for both 62 | python 2.x and python 3.x in the `dist` directory. 63 | 64 | For example: 65 | 66 | ```bash 67 | $ git clone git://github.com/SimpleITK/SimpleITKPythonPackage.git 68 | [...] 69 | 70 | $ ./scripts/dockcross-manylinux-build-wheels.sh 71 | [...] 72 | 73 | $ ls -1 dist/ 74 | SimpleITK-0.11.0-cp27-cp27m-manylinux1_i686.whl 75 | SimpleITK-0.11.0-cp27-cp27m-manylinux1_x86_64.whl 76 | SimpleITK-0.11.0-cp27-cp27mu-manylinux1_i686.whl 77 | SimpleITK-0.11.0-cp27-cp27mu-manylinux1_x86_64.whl 78 | SimpleITK-0.11.0-cp33-cp33m-manylinux1_i686.whl 79 | SimpleITK-0.11.0-cp33-cp33m-manylinux1_x86_64.whl 80 | SimpleITK-0.11.0-cp34-cp34m-manylinux1_i686.whl 81 | SimpleITK-0.11.0-cp34-cp34m-manylinux1_x86_64.whl 82 | SimpleITK-0.11.0-cp35-cp35m-manylinux1_i686.whl 83 | SimpleITK-0.11.0-cp35-cp35m-manylinux1_x86_64.whl 84 | ``` 85 | 86 | ## Prerequisites 87 | 88 | Building wheels requires: 89 | * [CMake](https://cmake.org) 90 | * Git 91 | * C++ Compiler - Platform specific requirements are summarized in [scikit-build documentation](http://scikit-build.readthedocs.io). 92 | * Python 93 | 94 | ## Detailed build instructions 95 | 96 | ### Building SimpleITK Python wheels 97 | 98 | Build the SimpleITK Python wheel with the following command: 99 | 100 | ``` 101 | python -m build . 102 | ``` 103 | ### Building Source Distribution 104 | 105 | The Python [build](https://pypa-build.readthedocs.io/en/latest/) package should be used to build the source distribution: 106 | 107 | ``` 108 | python -m build --sdist . 109 | ``` 110 | 111 | ### Efficiently building wheels for different version of python 112 | 113 | If on a given platform you would like to build wheels for different version of python, you can build the SimpleITK core libraries first and reuse them when building each wheel. 114 | 115 | Here are the steps: 116 | 117 | 1. Build `SimpleITKPythonPackage` with `SimpleITKPythonPackage_BUILD_PYTHON` set to `OFF` 118 | 119 | 2. Build "flavor" of package using: 120 | 121 | ``` 122 | python setup.py bdist_wheel -- \ 123 | -DSimpleITK_DIR:PATH=/path/to/SimpleITKPythonPackage-core-build/SimpleITK-superbuild/SimpleITK-build \ 124 | -DSWIG_EXECUTABLE:PATH=/path/to/SimpleITKPythonPackage-core-build/SimpleITK-superbuild/Swig/bin/swig 125 | ``` 126 | 127 | ## Miscellaneous 128 | Written by Jean-Christophe Fillion-Robin from Kitware Inc. 129 | 130 | It is covered by the Apache License, Version 2.0: 131 | 132 | http://www.apache.org/licenses/LICENSE-2.0 133 | 134 | For more information about SimpleITK, visit http://simpleitk.org 135 | 136 | For more information about ITK, visit http://itk.org 137 | 138 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "scikit-build>=0.17.6", 4 | "wheel", 5 | "cmake>=3.26.0", 6 | "ninja; platform_system!='Windows'" 7 | ] 8 | build-backend = "setuptools.build_meta" 9 | -------------------------------------------------------------------------------- /scripts/dockcross-manylinux-build-wheels.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Pull dockcross manylinux images 4 | docker pull dockcross/manylinux-x64 5 | docker pull dockcross/manylinux-x86 6 | 7 | # Generate dockcross scripts 8 | docker run dockcross/manylinux-x64 > /tmp/dockcross-manylinux-x64 && chmod u+x /tmp/dockcross-manylinux-x64 9 | docker run dockcross/manylinux-x86 > /tmp/dockcross-manylinux-x86 && chmod u+x /tmp/dockcross-manylinux-x86 10 | 11 | script_dir="`cd $(dirname $0); pwd`" 12 | 13 | # Build wheels 14 | pushd $script_dir/.. 15 | mkdir -p dist 16 | DOCKER_ARGS="-v $(pwd)/dist:/work/dist/" 17 | /tmp/dockcross-manylinux-x64 -a "$DOCKER_ARGS" ./scripts/internal/manylinux-build-wheels.sh 18 | /tmp/dockcross-manylinux-x86 -a "$DOCKER_ARGS" ./scripts/internal/manylinux-build-wheels.sh 19 | popd 20 | -------------------------------------------------------------------------------- /scripts/internal/manylinux-build-wheels.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e -x 3 | 4 | # i686 or x86_64 ? 5 | case $(uname -p) in 6 | i686) 7 | arch=x86 8 | ;; 9 | x86_64) 10 | arch=x64 11 | ;; 12 | *) 13 | die "Unknown architecture $(uname -p)" 14 | ;; 15 | esac 16 | 17 | echo "Building wheels for $arch" 18 | 19 | # Build standalone project and populate archive cache 20 | mkdir -p /work/standalone-${arch}-build 21 | pushd /work/standalone-${arch}-build > /dev/null 2>&1 22 | cmake -DSimpleITKPythonPackage_BUILD_PYTHON:PATH=0 -G Ninja ../ 23 | ninja 24 | popd > /dev/null 2>&1 25 | 26 | # Since the python interpreter exports its symbol (see [1]), python 27 | # modules should not link against any python libraries. 28 | # To ensure it is not the case, we configure the project using an empty 29 | # file as python library. 30 | # 31 | # [1] "Note that libpythonX.Y.so.1 is not on the list of libraries that 32 | # a manylinux1 extension is allowed to link to. Explicitly linking to 33 | # libpythonX.Y.so.1 is unnecessary in almost all cases: the way ELF linking 34 | # works, extension modules that are loaded into the interpreter automatically 35 | # get access to all of the interpreter's symbols, regardless of whether or 36 | # not the extension itself is explicitly linked against libpython. [...]" 37 | # 38 | # Source: https://www.python.org/dev/peps/pep-0513/#libpythonx-y-so-1 39 | PYTHON_LIBRARY=/work/scripts/internal/manylinux-libpython-not-needed-symbols-exported-by-interpreter 40 | touch ${PYTHON_LIBRARY} 41 | 42 | # Compile wheels re-using standalone project and archive cache 43 | for PYBIN in /opt/python/*/bin; do 44 | if [[ ${PYBIN} == *"cp26"* ]]; then 45 | echo "Skipping ${PYBIN}" 46 | continue 47 | fi 48 | 49 | PYTHON_EXECUTABLE=${PYBIN}/python 50 | PYTHON_INCLUDE_DIR=$( find -L ${PYBIN}/../include/ -name Python.h -exec dirname {} \; ) 51 | 52 | echo "" 53 | echo "PYTHON_EXECUTABLE:${PYTHON_EXECUTABLE}" 54 | echo "PYTHON_INCLUDE_DIR:${PYTHON_INCLUDE_DIR}" 55 | echo "PYTHON_LIBRARY:${PYTHON_LIBRARY}" 56 | 57 | ${PYBIN}/pip install -r /work/requirements-dev.txt 58 | ${PYBIN}/python setup.py bdist_wheel -G Ninja -- \ 59 | -DSimpleITK_DIR:PATH=/work/standalone-${arch}-build/SimpleITK-superbuild/SimpleITK-build \ 60 | -DSimpleITK_SOURCE_DIR:PATH=/work/standalone-${arch}-build/SimpleITK \ 61 | -DSWIG_EXECUTABLE:FILEPATH=/work/standalone-${arch}-build/SimpleITK-superbuild/Swig/bin/swig \ 62 | -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} \ 63 | -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} \ 64 | -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY} 65 | ${PYBIN}/python setup.py clean 66 | done 67 | 68 | # Since there are no external shared libraries to bundle into the wheels 69 | # this step will fixup the wheel switching from 'linux' to 'manylinux1' tag 70 | for whl in dist/*linux_$(uname -p).whl; do 71 | auditwheel repair $whl -w /work/dist/ 72 | rm $whl 73 | done 74 | 75 | # Install packages and test 76 | for PYBIN in /opt/python/*/bin/; do 77 | if [[ ${PYBIN} == *"cp26"* ]]; then 78 | echo "Skipping ${PYBIN}" 79 | continue 80 | fi 81 | ${PYBIN}/pip install SimpleITK --user --no-cache-dir --no-index -f /work/dist 82 | (cd $HOME; ${PYBIN}/python -c 'import SimpleITK as sitk; print(sitk.Version())') 83 | done 84 | -------------------------------------------------------------------------------- /scripts/internal/manylinux-libpython-not-needed-symbols-exported-by-interpreter: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SimpleITK/SimpleITKPythonPackage/8ffa8a4a532e259867bd0b27b7bf6d8f4ab4f187/scripts/internal/manylinux-libpython-not-needed-symbols-exported-by-interpreter -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | from os import sys 3 | from skbuild import setup 4 | 5 | with open('SimpleITK/Readme.md', encoding='utf-8') as f: 6 | long_description = f.read() 7 | 8 | 9 | setup( 10 | name='SimpleITK', 11 | version='2.5.0', 12 | author='Insight Software Consortium', 13 | author_email='insight-users@itk.org', 14 | packages=['SimpleITK'], 15 | package_dir={'SimpleITK':'SimpleITK'}, 16 | description=r'SimpleITK is a simplified interface to the Insight Toolkit (ITK) for image registration and segmentation', 17 | long_description = long_description, 18 | long_description_content_type='text/markdown', 19 | classifiers=[ 20 | "License :: OSI Approved :: Apache Software License", 21 | "Programming Language :: Python", 22 | "Programming Language :: C++", 23 | "Development Status :: 5 - Production/Stable", 24 | "Intended Audience :: Education", 25 | "Intended Audience :: Healthcare Industry", 26 | "Intended Audience :: Science/Research", 27 | "Topic :: Scientific/Engineering", 28 | "Topic :: Scientific/Engineering :: Medical Science Apps.", 29 | "Topic :: Scientific/Engineering :: Information Analysis", 30 | "Topic :: Software Development :: Libraries", 31 | "Operating System :: Microsoft :: Windows", 32 | "Operating System :: POSIX", 33 | "Operating System :: Unix", 34 | "Operating System :: MacOS" 35 | ], 36 | license='Apache', 37 | keywords = 'SimpleITK ITK InsightToolkit segmentation registration', 38 | url = r'http://simpleitk.org/', 39 | project_urls={ 40 | "Bug Tracker": "https://github.com/SimpleITK/SimpleITK/issues", 41 | "Documentation": "https://simpleitk.readthedocs.io/en/release/", 42 | "Source Code": "https://github.com/SimpleITK/SimpleITK", 43 | }, 44 | install_requires=[], 45 | zip_safe=False 46 | ) 47 | --------------------------------------------------------------------------------