Skip to content

Commit 9a956c0

Browse files
committed
DOC: setup.py was replaced with pyproject.toml builds
Since 2023 pyproject.toml is the only used mechanism for building python packages in ITK.
1 parent 6c31af9 commit 9a956c0

9 files changed

Lines changed: 152 additions & 244 deletions

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# ITK Python Package
22

3-
This project provides a `setup.py` script to build ITK Python binary
4-
packages and infrastructure to build ITK external module Python
5-
packages.
3+
This project configures pyproject.toml files and manages environmental
4+
variables needed to build ITK Python binary wheels on MacOS, Linux, and Windows platforms.
5+
Scripts are available for both [ITK infrastructure](https://github.com/insightSoftwareConsortium/ITK) and
6+
ITK external module Python packages.
67

78
The Insight Toolkit (ITK) is an open-source, cross-platform system that provides developers
89
with an extensive suite of software tools for image analysis.
@@ -16,14 +17,14 @@ or at the [ITK GitHub homepage](https://github.com/insightSoftwareConsortium/ITK
1617
- [Frequently Asked Questions](#frequently-asked-questions)
1718
- [Additional Information](#additional-information)
1819

19-
## Using ITK Python Packages
20+
## Using ITK Python Packages (pre-built, or locally built)
2021

2122
ITKPythonPackage scripts can be used to produce [Python](https://www.python.org/) packages
2223
for ITK and ITK external modules. The resulting packages can be
2324
hosted on the [Python Package Index (PyPI)](https://pypi.org/)
2425
for easy distribution.
2526

26-
### Installation
27+
### Installation of pre-built packages
2728

2829
To install baseline ITK Python packages:
2930

docs/Build_ITK_Module_Python_packages.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Congratulations! Your packages can be installed with the commands::
100100
python -m pip install itk-<your-short-module-name>
101101

102102
where `itk-<your-short-module-name>` is the short name for your module that is
103-
specified in your setup.py file.
103+
specified in the configured `pyproject.toml` file.
104104

105105
Automate PyPI Package Uploads
106106
-----------------------------
@@ -118,7 +118,7 @@ and for the scope use::
118118
itk-<your-short-module-name>
119119

120120
where `<your-short-module-name>` is the short name for your module that is
121-
specified in your setup.py file. That scope will be available if you have
121+
specified in your configured `pyproject.toml` file. That scope will be available if you have
122122
already uploaded a first set of wheels via twine as described above; and that
123123
is the recommended approach. Otherwise, if you are creating the project at
124124
this time, choose an unlimited scope, but be careful with the created token.
@@ -137,7 +137,7 @@ individual package as a best practice.
137137
:alt: GitHub PyPI token secret
138138

139139
To push packages to PyPI, first, make sure to update the `version` for your
140-
package in the *setup.py* file. The initial version might be `0.1.0` or
140+
package in the *pyproject.toml* file. The initial version might be `0.1.0` or
141141
`1.0.0`. Subsequent versions should follow
142142
`semantic versioning <https://semver.org/>`_.
143143

docs/Build_ITK_Python_packages.rst

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -94,38 +94,39 @@ files are created and deleted quickly, which can result in Access Denied
9494
errors. Windows 10 ships with an antivirus application, Windows Defender, that
9595
is enabled by default.
9696

97-
sdist
98-
-----
99-
100-
To create source distributions, sdist's, that will be used by pip to compile a wheel for installation if a binary wheel is not available for the current Python version or platform::
101-
102-
$ python setup.py sdist --formats=gztar,zip
103-
[...]
104-
105-
$ ls -1 dist/
106-
itk-4.11.0.dev20170216.tar.gz
107-
itk-4.11.0.dev20170216.zip
108-
109-
Manual builds
110-
=============
111-
112-
Building ITK Python wheels
113-
--------------------------
114-
115-
Build the ITK Python wheel with the following command::
116-
117-
python3 -m venv build-itk
118-
./build-itk/bin/pip install --upgrade pip
119-
./build-itk/bin/pip install -r requirements-dev.txt numpy
120-
./build-itk/bin/python setup.py bdist_wheel
121-
122-
Build a wheel for a custom version of ITK
123-
-----------------------------------------
124-
125-
To build a wheel for a custom version of ITK, point to your ITK git repository
126-
with the `ITK_SOURCE_DIR` CMake variable::
127-
128-
./build-itk/bin/python setup.py bdist_wheel -- \
129-
-DITK_SOURCE_DIR:PATH=/path/to/ITKPythonPackage-core-build/ITK
130-
131-
Other CMake variables can also be passed with `-D` after the double dash.
97+
.. The below instructions are outdated and need to be re-written
98+
.. sdist
99+
.. -----
100+
..
101+
.. To create source distributions, sdist's, that will be used by pip to compile a wheel for installation if a binary wheel is not available for the current Python version or platform::
102+
..
103+
.. $ python setup.py sdist --formats=gztar,zip
104+
.. [...]
105+
..
106+
.. $ ls -1 dist/
107+
.. itk-4.11.0.dev20170216.tar.gz
108+
.. itk-4.11.0.dev20170216.zip
109+
..
110+
.. Manual builds
111+
.. =============
112+
..
113+
.. Building ITK Python wheels
114+
.. --------------------------
115+
..
116+
.. Build the ITK Python wheel with the following command::
117+
..
118+
.. python3 -m venv build-itk
119+
.. ./build-itk/bin/pip install --upgrade pip
120+
.. ./build-itk/bin/pip install -r requirements-dev.txt numpy
121+
.. ./build-itk/bin/python setup.py bdist_wheel
122+
..
123+
.. Build a wheel for a custom version of ITK
124+
.. -----------------------------------------
125+
..
126+
.. To build a wheel for a custom version of ITK, point to your ITK git repository
127+
.. with the `ITK_SOURCE_DIR` CMake variable::
128+
..
129+
.. ./build-itk/bin/python setup.py bdist_wheel -- \
130+
.. -DITK_SOURCE_DIR:PATH=/path/to/ITKPythonPackage-core-build/ITK
131+
..
132+
.. Other CMake variables can also be passed with `-D` after the double dash.

docs/index.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
Welcome to ITKPythonPackage's documentation!
22
============================================
33

4-
This project provides a ``setup.py`` script to build ITK Python wheels and
5-
infrastructure to build ITK external module Python wheels.
4+
This project provides a script to generate `pyproject.toml` files used to build
5+
ITK Python wheels and infrastructure to build ITK external module Python
6+
wheels.
67

7-
`ITK <https://www.itk.org/>`_ is an open-source, cross-platform system that provides developers with an extensive suite of software tools for image analysis.
8+
`ITK <https://www.itk.org/>`_ is an open-source, cross-platform system that
9+
provides developers with an extensive suite of software tools for image
10+
analysis.
811

9-
To install the stable ITK Python package::
12+
To install the pre-built stable ITK Python package::
1013

1114
$ pip install itk
1215

scripts/internal/manylinux-build-module-wheels.sh

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ source "${script_dir}/manylinux-build-common.sh"
7373
sudo ldconfig
7474
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/work/oneTBB-prefix/lib:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64
7575

76-
if test -e setup.py; then
77-
use_skbuild_classic=true
78-
else
79-
use_skbuild_classic=false
80-
fi
81-
8276
# Compile wheels re-using standalone project and archive cache
8377
for PYBIN in "${PYBINARIES[@]}"; do
8478
Python3_EXECUTABLE=${PYBIN}/python
@@ -88,11 +82,6 @@ for PYBIN in "${PYBINARIES[@]}"; do
8882
echo "Python3_EXECUTABLE:${Python3_EXECUTABLE}"
8983
echo "Python3_INCLUDE_DIR:${Python3_INCLUDE_DIR}"
9084

91-
if $use_skbuild_classic; then
92-
# So older remote modules with setup.py continue to work
93-
${Python3_EXECUTABLE} -m pip install --upgrade scikit-build
94-
fi
95-
9685
if [[ -e /work/requirements-dev.txt ]]; then
9786
${PYBIN}/pip install --upgrade -r /work/requirements-dev.txt
9887
fi
@@ -114,42 +103,28 @@ for PYBIN in "${PYBINARIES[@]}"; do
114103
echo 'ITK source tree not available!' 1>&2
115104
exit 1
116105
fi
117-
if $use_skbuild_classic; then
118-
${PYBIN}/python setup.py clean
119-
${PYBIN}/python setup.py bdist_wheel --build-type Release -G Ninja -- \
120-
-DITK_DIR:PATH=${itk_build_dir} \
121-
-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \
122-
-DCMAKE_CXX_COMPILER_TARGET:STRING=$(uname -m)-linux-gnu \
123-
-DCMAKE_INSTALL_LIBDIR:STRING=lib \
124-
-DBUILD_TESTING:BOOL=OFF \
125-
-DPython3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
126-
-DPython3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
127-
${CMAKE_OPTIONS} \
128-
|| exit 1
129-
else
130-
py_minor=$(echo $version | cut -d '-' -f 1 | cut -d '3' -f 2)
131-
wheel_py_api=""
132-
if test $py_minor -ge 11; then
133-
wheel_py_api=cp3$py_minor
134-
fi
135-
${PYBIN}/python -m build \
136-
--verbose \
137-
--wheel \
138-
--outdir dist \
139-
--no-isolation \
140-
--skip-dependency-check \
141-
--config-setting=cmake.define.ITK_DIR:PATH=${itk_build_dir} \
142-
--config-setting=cmake.define.WRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \
143-
--config-setting=cmake.define.CMAKE_CXX_COMPILER_TARGET:STRING=$(uname -m)-linux-gnu \
144-
--config-setting=cmake.define.CMAKE_INSTALL_LIBDIR:STRING=lib \
145-
--config-setting=cmake.define.PY_SITE_PACKAGES_PATH:PATH="." \
146-
--config-setting=wheel.py-api=$wheel_py_api \
147-
--config-setting=cmake.define.BUILD_TESTING:BOOL=OFF \
148-
--config-setting=cmake.define.Python3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
149-
--config-setting=cmake.define.Python3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
150-
${CMAKE_OPTIONS//'-D'/'--config-setting=cmake.define.'} \
151-
|| exit 1
106+
py_minor=$(echo $version | cut -d '-' -f 1 | cut -d '3' -f 2)
107+
wheel_py_api=""
108+
if test $py_minor -ge 11; then
109+
wheel_py_api=cp3$py_minor
152110
fi
111+
${PYBIN}/python -m build \
112+
--verbose \
113+
--wheel \
114+
--outdir dist \
115+
--no-isolation \
116+
--skip-dependency-check \
117+
--config-setting=cmake.define.ITK_DIR:PATH=${itk_build_dir} \
118+
--config-setting=cmake.define.WRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \
119+
--config-setting=cmake.define.CMAKE_CXX_COMPILER_TARGET:STRING=$(uname -m)-linux-gnu \
120+
--config-setting=cmake.define.CMAKE_INSTALL_LIBDIR:STRING=lib \
121+
--config-setting=cmake.define.PY_SITE_PACKAGES_PATH:PATH="." \
122+
--config-setting=wheel.py-api=$wheel_py_api \
123+
--config-setting=cmake.define.BUILD_TESTING:BOOL=OFF \
124+
--config-setting=cmake.define.Python3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
125+
--config-setting=cmake.define.Python3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
126+
${CMAKE_OPTIONS//'-D'/'--config-setting=cmake.define.'} \
127+
|| exit 1
153128
done
154129

155130
# Convert list of excluded libs in --exclude_libs to auditwheel --exclude options
@@ -160,9 +135,6 @@ fi
160135
sudo ${Python3_EXECUTABLE} -m pip install auditwheel
161136
for whl in dist/*linux*$(uname -m).whl; do
162137
auditwheel repair ${whl} -w /work/dist/ ${AUDITWHEEL_EXCLUDE_ARGS}
163-
if $use_skbuild_classic; then
164-
rm ${whl}
165-
fi
166138
done
167139

168140
if compgen -G "dist/itk*-linux*.whl" > /dev/null; then

scripts/macpython-build-module-wheels.sh

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ VENVS=()
6262
source "${script_dir}/macpython-build-common.sh"
6363
# -----------------------------------------------------------------------
6464

65-
if test -e setup.py; then
66-
use_skbuild_classic=true
67-
else
68-
use_skbuild_classic=false
69-
fi
70-
71-
7265
VENV="${VENVS[0]}"
7366
Python3_EXECUTABLE=${VENV}/bin/python3
7467
dot_clean ${VENV}
@@ -89,11 +82,6 @@ for VENV in "${VENVS[@]}"; do
8982
echo "Python3_EXECUTABLE:${Python3_EXECUTABLE}"
9083
echo "Python3_INCLUDE_DIR:${Python3_INCLUDE_DIR}"
9184

92-
if $use_skbuild_classic; then
93-
# So older remote modules with setup.py continue to work
94-
${Python3_EXECUTABLE} -m pip install --upgrade scikit-build
95-
fi
96-
9785
if [[ $(arch) == "arm64" ]]; then
9886
plat_name="macosx-15.0-arm64"
9987
osx_target="15.0"
@@ -114,45 +102,30 @@ for VENV in "${VENVS[@]}"; do
114102
${Python3_EXECUTABLE} -m pip install --upgrade -r $PWD/requirements-dev.txt
115103
fi
116104
itk_build_path="${build_path}"
117-
if $use_skbuild_classic; then
118-
${Python3_EXECUTABLE} setup.py bdist_wheel --build-type Release --plat-name ${plat_name} -G Ninja -- \
119-
-DCMAKE_MAKE_PROGRAM:FILEPATH=${NINJA_EXECUTABLE} \
120-
-DITK_DIR:PATH=${itk_build_path} \
121-
-DCMAKE_INSTALL_LIBDIR:STRING=lib \
122-
-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \
123-
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${osx_target} \
124-
-DCMAKE_OSX_ARCHITECTURES:STRING=${osx_arch} \
125-
-DBUILD_TESTING:BOOL=OFF \
126-
-DPython3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
127-
-DPython3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
128-
${CMAKE_OPTIONS} \
129-
|| exit 1
130-
else
131-
py_minor=$(echo $py_mm | cut -d '.' -f 2)
132-
wheel_py_api=""
133-
if test $py_minor -ge 11; then
134-
wheel_py_api=cp3$py_minor
135-
fi
136-
${Python3_EXECUTABLE} -m build \
137-
--verbose \
138-
--wheel \
139-
--outdir dist \
140-
--no-isolation \
141-
--skip-dependency-check \
142-
--config-setting=cmake.define.CMAKE_MAKE_PROGRAM:FILEPATH=${NINJA_EXECUTABLE} \
143-
--config-setting=cmake.define.ITK_DIR:PATH=${itk_build_path} \
144-
--config-setting=cmake.define.CMAKE_INSTALL_LIBDIR:STRING=lib \
145-
--config-setting=cmake.define.WRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \
146-
--config-setting=cmake.define.CMAKE_OSX_DEPLOYMENT_TARGET:STRING=${osx_target} \
147-
--config-setting=cmake.define.CMAKE_OSX_ARCHITECTURES:STRING=${osx_arch} \
148-
--config-setting=cmake.define.PY_SITE_PACKAGES_PATH:PATH="." \
149-
--config-setting=wheel.py-api=$wheel_py_api \
150-
--config-setting=cmake.define.BUILD_TESTING:BOOL=OFF \
151-
--config-setting=cmake.define.Python3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
152-
--config-setting=cmake.define.Python3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
153-
${CMAKE_OPTIONS//'-D'/'--config-setting=cmake.define.'} \
154-
|| exit 1
105+
py_minor=$(echo $py_mm | cut -d '.' -f 2)
106+
wheel_py_api=""
107+
if test $py_minor -ge 11; then
108+
wheel_py_api=cp3$py_minor
155109
fi
110+
${Python3_EXECUTABLE} -m build \
111+
--verbose \
112+
--wheel \
113+
--outdir dist \
114+
--no-isolation \
115+
--skip-dependency-check \
116+
--config-setting=cmake.define.CMAKE_MAKE_PROGRAM:FILEPATH=${NINJA_EXECUTABLE} \
117+
--config-setting=cmake.define.ITK_DIR:PATH=${itk_build_path} \
118+
--config-setting=cmake.define.CMAKE_INSTALL_LIBDIR:STRING=lib \
119+
--config-setting=cmake.define.WRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \
120+
--config-setting=cmake.define.CMAKE_OSX_DEPLOYMENT_TARGET:STRING=${osx_target} \
121+
--config-setting=cmake.define.CMAKE_OSX_ARCHITECTURES:STRING=${osx_arch} \
122+
--config-setting=cmake.define.PY_SITE_PACKAGES_PATH:PATH="." \
123+
--config-setting=wheel.py-api=$wheel_py_api \
124+
--config-setting=cmake.define.BUILD_TESTING:BOOL=OFF \
125+
--config-setting=cmake.define.Python3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
126+
--config-setting=cmake.define.Python3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
127+
${CMAKE_OPTIONS//'-D'/'--config-setting=cmake.define.'} \
128+
|| exit 1
156129
done
157130

158131
for wheel in $PWD/dist/*.whl; do

scripts/pyproject_configure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def from_group_to_wheel(group):
121121
return "itk-%s" % group.lower()
122122

123123

124-
def update_wheel_setup_py_parameters():
124+
def update_wheel_pyproject_toml_parameters():
125125
global PYPROJECT_PY_PARAMETERS
126126
for wheel_name in get_wheel_names():
127127
params = dict(ITK_PYPROJECT_PY_PARAMETERS)
@@ -291,7 +291,7 @@ def get_wheel_dependencies():
291291

292292
PYPROJECT_PY_PARAMETERS = {"itk": ITK_PYPROJECT_PY_PARAMETERS}
293293

294-
update_wheel_setup_py_parameters()
294+
update_wheel_pyproject_toml_parameters()
295295

296296

297297
def main():

scripts/windows-download-cache-and-build-module-wheels.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
# or equivalently:
1313
# > windows-download-cache-and-build-module-wheels.ps1 -python_version_minor 11
1414
#
15-
# - 1st parameter or -setup_options: setup.py options.
15+
# - 1st parameter or -setup_options: pyproject.toml options.
1616
# For instance, for Python 3.11, excluding nvcuda.dll during packaging:
1717
# > windows-download-cache-and-build-module-wheels.ps1 11 "--exclude-libs nvcuda.dll"
1818
# or equivalently:
1919
# > windows-download-cache-and-build-module-wheels.ps1 -python_version_minor 11 -setup_options "--exclude-libs nvcuda.dll"
2020
#
21-
# - 2nd parameter or -cmake_options: CMake options passed to setup.py for project configuration.
21+
# - 2nd parameter or -cmake_options: CMake options passed to pyproject.tom for project configuration.
2222
# For instance, for Python 3.11, excluding nvcuda.dll during packaging
2323
# and setting RTK_USE_CUDA ON during configuration:
2424
# > windows-download-cache-and-build-module-wheels.ps1 11 "--exclude-libs nvcuda.dll" "-DRTK_USE_CUDA:BOOL=ON"

0 commit comments

Comments
 (0)