Skip to content

Commit 2d7ece0

Browse files
committed
WIP: ENH: migrate to scikit-build-core, linux amd64
Supporting the Stable ABI / Limited API.
1 parent 7e5742a commit 2d7ece0

File tree

9 files changed

+244
-284
lines changed

9 files changed

+244
-284
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ lib
4343
lib64
4444
MANIFEST
4545
oneTBB-prefix/
46+
pyproject.toml
4647

4748
# Installer logs
4849
pip-log.txt

CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ if(ITKPythonPackage_SUPERBUILD)
4848
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
4949
)
5050
endif()
51+
set(ep_download_extract_timestamp_arg )
52+
if(CMAKE_VERSION VERSION_EQUAL "3.24" OR CMAKE_VERSION VERSION_GREATER "3.24")
53+
# See https://cmake.org/cmake/help/latest/policy/CMP0135.html
54+
set(ep_download_extract_timestamp_arg DOWNLOAD_EXTRACT_TIMESTAMP 1)
55+
endif()
5156

5257
#-----------------------------------------------------------------------------
5358
# Options
@@ -124,6 +129,7 @@ if(ITKPythonPackage_SUPERBUILD)
124129
-DCMAKE_INSTALL_LIBDIR:STRING=lib # Skip default initialization by GNUInstallDirs CMake module
125130
${ep_common_cmake_cache_args}
126131
${tbb_cmake_cache_args}
132+
${ep_download_extract_timestamp_arg}
127133
-DCMAKE_BUILD_TYPE:STRING=Release
128134
BUILD_BYPRODUCTS "${TBB_DIR}/TBBConfig.cmake"
129135
USES_TERMINAL_DOWNLOAD 1
@@ -276,18 +282,14 @@ if(ITKPythonPackage_SUPERBUILD)
276282
-DWRAP_ITK_INSTALL_COMPONENT_PER_MODULE:BOOL=${install_component_per_module}
277283
-DITK_LEGACY_SILENT:BOOL=ON
278284
-DITK_WRAP_PYTHON:BOOL=ON
279-
-DITK_WRAP_unsigned_short:BOOL=ON
280-
-DITK_WRAP_double:BOOL=ON
281-
-DITK_WRAP_complex_double:BOOL=ON
282-
-DITK_WRAP_IMAGE_DIMS:STRING=2;3;4
283-
-DITK_WRAP_DOC:BOOL=ON
284285
-DDOXYGEN_EXECUTABLE:FILEPATH=${DOXYGEN_EXECUTABLE}
285286
-DPython3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR}
286287
-DPython3_LIBRARY:FILEPATH=${Python3_LIBRARY}
287288
-DPython3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE}
288289
${ep_common_cmake_cache_args}
289290
${tbb_args}
290291
${ep_itk_cmake_cache_args}
292+
${ep_download_extract_timestamp_arg}
291293
USES_TERMINAL_DOWNLOAD 1
292294
USES_TERMINAL_UPDATE 1
293295
USES_TERMINAL_CONFIGURE 1

MANIFEST.in

Lines changed: 0 additions & 8 deletions
This file was deleted.

requirements-dev.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
ninja==1.11.1
2-
scikit-build==0.17.6
1+
ninja==1.11.1.1
2+
scikit-build-core==0.8.2

scripts/internal/manylinux-build-wheels.sh

Lines changed: 39 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ tbb_dir=/work/oneTBB-prefix/lib/cmake/TBB
4949
sudo ldconfig
5050
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/work/oneTBB-prefix/lib:/usr/lib:/usr/lib64
5151

52+
# TODO: More work is required to re-enable this feature.
5253
SINGLE_WHEEL=0
5354

5455
# Compile wheels re-using standalone project and archive cache
@@ -67,8 +68,7 @@ for PYBIN in "${PYBINARIES[@]}"; do
6768
compile_flags="-O3 -DNDEBUG"
6869
source_path=/work/ITK-source/ITK
6970
build_path=/work/ITK-$(basename $(dirname ${PYBIN}))-manylinux${MANYLINUX_VERSION}_${ARCH}
70-
SETUP_PY_CONFIGURE="${script_dir}/../setup_py_configure.py"
71-
SKBUILD_CMAKE_INSTALL_PREFIX=$(${Python3_EXECUTABLE} -c "from skbuild.constants import CMAKE_INSTALL_DIR; print(CMAKE_INSTALL_DIR)")
71+
PYPROJECT_CONFIGURE="${script_dir}/../pyproject_configure.py"
7272

7373
# Clean up previous invocations
7474
rm -rf ${build_path}
@@ -80,28 +80,26 @@ for PYBIN in "${PYBINARIES[@]}"; do
8080
echo "#"
8181

8282
# Configure setup.py
83-
${PYBIN}/python ${SETUP_PY_CONFIGURE} "itk"
83+
${PYBIN}/python ${PYPROJECT_CONFIGURE} "itk"
8484
# Generate wheel
85-
${PYBIN}/python setup.py bdist_wheel -G Ninja -- \
86-
-DITK_SOURCE_DIR:PATH=${source_path} \
87-
-DITK_BINARY_DIR:PATH=${build_path} \
88-
-DITKPythonPackage_ITK_BINARY_REUSE:BOOL=OFF \
89-
-DITKPythonPackage_WHEEL_NAME:STRING="itk" \
90-
-DITK_WRAP_unsigned_short:BOOL=ON \
91-
-DITK_WRAP_double:BOOL=ON \
92-
-DITK_WRAP_complex_double:BOOL=ON \
93-
-DITK_WRAP_IMAGE_DIMS:STRING="2;3;4" \
94-
-DCMAKE_CXX_COMPILER_TARGET:STRING=$(uname -m)-linux-gnu \
95-
-DCMAKE_CXX_FLAGS:STRING="$compile_flags" \
96-
-DCMAKE_C_FLAGS:STRING="$compile_flags" \
97-
-DCMAKE_BUILD_TYPE:STRING="${build_type}" \
98-
-DPython3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
99-
-DPython3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
100-
-DModule_ITKTBB:BOOL=ON \
101-
-DTBB_DIR:PATH=${tbb_dir} \
102-
-DITK_WRAP_DOC:BOOL=ON
103-
# Cleanup
104-
${PYBIN}/python setup.py clean
85+
${PYBIN}/python -m pip \
86+
--verbose \
87+
wheel \
88+
--wheel-dir dist \
89+
--no-deps \
90+
--config-settings=cmake.define.ITK_SOURCE_DIR:PATH=${source_path} \
91+
--config-settings=cmake.define.ITK_BINARY_DIR:PATH=${build_path} \
92+
--config-settings=cmake.define.ITKPythonPackage_ITK_BINARY_REUSE:BOOL=OFF \
93+
--config-settings=cmake.define.ITKPythonPackage_WHEEL_NAME:STRING=itk \
94+
--config-settings=cmake.define.CMAKE_CXX_COMPILER_TARGET:STRING=$(uname -m)-linux-gnu \
95+
"--config-settings=cmake.define.CMAKE_CXX_FLAGS:STRING=$compile_flags" \
96+
"--config-settings=cmake.define.CMAKE_C_FLAGS:STRING=$compile_flags" \
97+
"--config-settings=cmake.define.CMAKE_BUILD_TYPE:STRING=${build_type}" \
98+
--config-settings=cmake.define.Python3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
99+
--config-settings=cmake.define.Python3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
100+
--config-settings=cmake.define.Module_ITKTBB:BOOL=ON \
101+
--config-settings=cmake.define.TBB_DIR:PATH=${tbb_dir} \
102+
.
105103

106104
else
107105

@@ -145,26 +143,23 @@ for PYBIN in "${PYBINARIES[@]}"; do
145143
wheel_names=$(cat ${script_dir}/../WHEEL_NAMES.txt)
146144
for wheel_name in ${wheel_names}; do
147145
# Configure setup.py
148-
${PYBIN}/python ${SETUP_PY_CONFIGURE} ${wheel_name}
146+
${PYBIN}/python ${PYPROJECT_CONFIGURE} ${wheel_name}
149147
# Generate wheel
150-
${PYBIN}/python setup.py bdist_wheel -G Ninja -- \
151-
-DITK_SOURCE_DIR:PATH=${source_path} \
152-
-DITK_BINARY_DIR:PATH=${build_path} \
153-
-DITKPythonPackage_ITK_BINARY_REUSE:BOOL=ON \
154-
-DITKPythonPackage_WHEEL_NAME:STRING=${wheel_name} \
155-
-DITK_WRAP_unsigned_short:BOOL=ON \
156-
-DITK_WRAP_double:BOOL=ON \
157-
-DITK_WRAP_complex_double:BOOL=ON \
158-
-DITK_WRAP_IMAGE_DIMS:STRING="2;3;4" \
159-
-DPython3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
160-
-DPython3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
161-
-DCMAKE_BUILD_TYPE:STRING="${build_type}" \
162-
-DCMAKE_CXX_FLAGS:STRING="${compile_flags}" \
163-
-DCMAKE_C_FLAGS:STRING="${compile_flags}" \
164-
-DITK_WRAP_DOC:BOOL=ON \
148+
${PYBIN}/python -m pip \
149+
--verbose \
150+
wheel \
151+
--wheel-dir dist \
152+
--no-deps \
153+
--config-settings=cmake.define.ITK_SOURCE_DIR:PATH=${source_path} \
154+
--config-settings=cmake.define.ITK_BINARY_DIR:PATH=${build_path} \
155+
--config-settings=cmake.define.ITKPythonPackage_ITK_BINARY_REUSE:BOOL=ON \
156+
--config-settings=cmake.define.ITKPythonPackage_WHEEL_NAME:STRING=${wheel_name} \
157+
--config-settings=cmake.define.Python3_EXECUTABLE:FILEPATH=${Python3_EXECUTABLE} \
158+
--config-settings=cmake.define.Python3_INCLUDE_DIR:PATH=${Python3_INCLUDE_DIR} \
159+
--config-settings=cmake.define.CMAKE_CXX_FLAGS:STRING="${compile_flags}" \
160+
--config-settings=cmake.define.CMAKE_C_FLAGS:STRING="${compile_flags}" \
161+
. \
165162
|| exit 1
166-
# Cleanup
167-
${PYBIN}/python setup.py clean
168163
done
169164
fi
170165

@@ -178,37 +173,15 @@ done
178173
if test "${ARCH}" == "x64"; then
179174
sudo /opt/python/cp39-cp39/bin/pip3 install auditwheel wheel
180175
# This step will fixup the wheel switching from 'linux' to 'manylinux<version>' tag
181-
for whl in dist/itk_*linux_$(uname -m).whl; do
176+
for whl in dist/itk_*linux_*.whl; do
182177
/opt/python/cp39-cp39/bin/auditwheel repair --plat manylinux${MANYLINUX_VERSION}_x86_64 ${whl} -w /work/dist/
183-
rm ${whl}
184178
done
185179
else
186180
for whl in dist/itk_*$(uname -m).whl; do
187181
auditwheel repair ${whl} -w /work/dist/
188182
rm ${whl}
189183
done
190184
fi
191-
itk_core_whl=$(ls dist/itk_core*whl | head -n 1)
192-
repaired_plat1=$(echo $itk_core_whl | cut -d- -f5 | cut -d. -f1)
193-
repaired_plat2=$(echo $itk_core_whl | cut -d- -f5 | cut -d. -f2)
194-
for itk_wheel in dist/itk*-linux*.whl; do
195-
mkdir -p unpacked_whl packed_whl
196-
/opt/python/cp39-cp39/bin/wheel unpack -d unpacked_whl ${itk_wheel}
197-
version=$(echo ${itk_wheel} | cut -d- -f3-4)
198-
echo "Wheel-Version: 1.0" > unpacked_whl/itk-*/*.dist-info/WHEEL
199-
echo "Generator: skbuild 0.8.1" >> unpacked_whl/itk-*/*.dist-info/WHEEL
200-
echo "Root-Is-Purelib: false" >> unpacked_whl/itk-*/*.dist-info/WHEEL
201-
echo "Tag: ${version}-${repaired_plat1}" >> unpacked_whl/itk-*/*.dist-info/WHEEL
202-
echo "Tag: ${version}-${repaired_plat2}" >> unpacked_whl/itk-*/*.dist-info/WHEEL
203-
echo "" >> unpacked_whl/itk-*/*.dist-info/WHEEL
204-
/opt/python/cp39-cp39/bin/wheel pack -d packed_whl ./unpacked_whl/itk-*
205-
mv packed_whl/*.whl dist/
206-
rm -rf unpacked_whl packed_whl ${itk_wheel}
207-
done
208-
209-
for itk_wheel in dist/itk*.whl.whl; do
210-
mv $itk_wheel dist/$(basename $itk_wheel .whl)
211-
done
212185

213186
# Install packages and test
214187
for PYBIN in "${PYBINARIES[@]}"; do
@@ -219,3 +192,5 @@ for PYBIN in "${PYBINARIES[@]}"; do
219192
(cd $HOME && ${PYBIN}/python -c 'import itkConfig; itkConfig.LazyLoading = False; import itk;')
220193
(cd $HOME && ${PYBIN}/python ${script_dir}/../../docs/code/test.py )
221194
done
195+
196+
rm -f dist/numpy*.whl

scripts/pyproject.toml.in

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Generated using: @PYPROJECT_GENERATOR@
2+
3+
[build-system]
4+
requires = ["scikit-build-core"]
5+
build-backend = "scikit_build_core.build"
6+
7+
[project]
8+
name = "@PYPROJECT_NAME@"
9+
version = "@PYPROJECT_VERSION@"
10+
11+
description = "@PYPROJECT_DESCRIPTION@"
12+
readme = "ITK-source/ITK/README.md"
13+
license = {file = "LICENSE"}
14+
authors = [
15+
{ name = "Insight Software Consortium", email = "[email protected]" },
16+
]
17+
keywords = [
18+
"ITK",
19+
"InsightToolkit",
20+
@PYPROJECT_EXTRA_KEYWORDS@
21+
]
22+
classifiers = [
23+
"Development Status :: 4 - Beta",
24+
"Intended Audience :: Developers",
25+
"Intended Audience :: Education",
26+
"Intended Audience :: Healthcare Industry",
27+
"Intended Audience :: Science/Research",
28+
"License :: OSI Approved :: Apache Software License",
29+
"Operating System :: Android",
30+
"Operating System :: MacOS",
31+
"Operating System :: Microsoft :: Windows",
32+
"Operating System :: POSIX",
33+
"Operating System :: Unix",
34+
"Programming Language :: C++",
35+
"Programming Language :: Python",
36+
"Programming Language :: Python :: 3",
37+
"Topic :: Scientific/Engineering",
38+
"Topic :: Scientific/Engineering :: Information Analysis",
39+
"Topic :: Scientific/Engineering :: Medical Science Apps.",
40+
"Topic :: Software Development :: Libraries",
41+
]
42+
requires-python = ">=3.8"
43+
dependencies = [
44+
@PYPROJECT_DEPENDENCIES@
45+
]
46+
47+
[project.urls]
48+
Download = "@PYPROJECT_DOWNLOAD_URL@"
49+
Home = "https://docs.itk.org/"
50+
Issues = "https://github.com/InsightSoftwareConsortium/ITK/issues"
51+
Source = "https://github.com/InsightSoftwareConsortium/ITK"
52+
53+
[tool.scikit-build]
54+
# The versions of CMake to allow. If CMake is not present on the system or does
55+
# not pass this specifier, it will be downloaded via PyPI if possible. An empty
56+
# string will disable this check.
57+
cmake.version = ">=3.16"
58+
59+
# A list of args to pass to CMake when configuring the project. Setting this in
60+
# config or envvar will override toml. See also ``cmake.define``.
61+
cmake.args = [@PYPROJECT_CMAKE_ARGS@]
62+
63+
# A table of defines to pass to CMake when configuring the project. Additive.
64+
cmake.define = {}
65+
66+
# Verbose printout when building.
67+
cmake.verbose = true
68+
69+
# The build type to use when building the project. Valid options are: "Debug",
70+
# "Release", "RelWithDebInfo", "MinSizeRel", "", etc.
71+
cmake.build-type = "Release"
72+
73+
# The source directory to use when building the project. Currently only affects
74+
# the native builder (not the setuptools plugin).
75+
cmake.source-dir = "."
76+
77+
# The versions of Ninja to allow. If Ninja is not present on the system or does
78+
# not pass this specifier, it will be downloaded via PyPI if possible. An empty
79+
# string will disable this check.
80+
ninja.version = ">=1.11"
81+
82+
# If CMake is not present on the system or is older required, it will be
83+
# downloaded via PyPI if possible. An empty string will disable this check.
84+
ninja.make-fallback = true
85+
86+
# The logging level to display, "DEBUG", "INFO", "WARNING", and "ERROR" are
87+
# possible options.
88+
logging.level = "INFO"
89+
90+
# Files to include in the SDist even if they are skipped by default. Supports
91+
# gitignore syntax.
92+
sdist.include = ["CMakeLists.txt", "cmake/*.cmake", "README.md", "itkVersion.py", "pyproject.toml", "itk/__init__.py"]
93+
94+
# Files to exclude from the SDist even if they are included by default. Supports
95+
# gitignore syntax.
96+
sdist.exclude = ["scripts"]
97+
98+
# The Python tags. The default (empty string) will use the default Python
99+
# version. You can also set this to "cp37" to enable the CPython 3.7+ Stable ABI
100+
# / Limited API (only on CPython and if the version is sufficient, otherwise
101+
# this has no effect). Or you can set it to "py3" or "py2.py3" to ignore Python
102+
# ABI compatibility. The ABI tag is inferred from this tag.
103+
wheel.py-api = "@PYPROJECT_PY_API@"
104+
105+
# A list of license files to include in the wheel. Supports glob patterns.
106+
wheel.license-files = ["LICEN[CS]E*", "ITK-source/ITK/LICENSE", "ITK-source/ITK/NOTICE"]
107+
108+
# Target the platlib or the purelib. If not set, the default is to target the
109+
# platlib if wheel.cmake is true, and the purelib otherwise.
110+
wheel.platlib = "@PYPROJECT_PLATLIB@"
111+
112+
# If CMake is less than this value, backport a copy of FindPython. Set to 0
113+
# disable this, or the empty string.
114+
backport.find-python = "3.26.1"
115+
116+
# Select the editable mode to use. Can be "redirect" (default) or "inplace".
117+
editable.mode = "redirect"
118+
119+
# Rebuild the project when the package is imported. The build-directory must be
120+
# set.
121+
editable.rebuild = false
122+
123+
# The components to install. If empty, all default components are installed.
124+
install.components = []
125+
126+
# Whether to strip the binaries. True for scikit-build-core 0.5+.
127+
install.strip = true
128+
129+
# If set, this will provide a method for backward compatibility.
130+
minimum-version = "0.8.2"
131+
132+
# The build directory. Defaults to a temporary directory, but can be set.
133+
build-dir = "build/{wheel_tag}"

0 commit comments

Comments
 (0)