Skip to content

Commit 09292e4

Browse files
committed
ENH: scikit-build-core support for building Windows remote module wheels
scikit-build classic setup.py still works.
1 parent 3a86fdf commit 09292e4

File tree

1 file changed

+65
-23
lines changed

1 file changed

+65
-23
lines changed

scripts/windows_build_module_wheels.py

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99
import argparse
1010
import shutil
11+
from pathlib import Path
1112

1213
SCRIPT_DIR = os.path.dirname(__file__)
1314
ROOT_DIR = os.path.abspath(os.getcwd())
@@ -44,40 +45,81 @@ def build_wheels(py_envs=DEFAULT_PY_ENVS, cleanup=True, cmake_options=[]):
4445

4546
with push_env(PATH="%s%s%s" % (path, os.pathsep, os.environ["PATH"])):
4647

48+
use_scikit_build_core = True
49+
if Path(os.getcwd()).joinpath('setup.py').exists():
50+
use_scikit_build_core = False
51+
4752
# Install dependencies
53+
check_call([pip, "install", "pip", "--upgrade"])
4854
requirements_file = os.path.join(ROOT_DIR, "requirements-dev.txt")
4955
if os.path.exists(requirements_file):
5056
check_call([pip, "install", "--upgrade", "-r", requirements_file])
5157
check_call([pip, "install", "cmake"])
52-
check_call([pip, "install", "scikit_build", "--upgrade"])
53-
check_call([pip, "install", "ninja"])
58+
if use_scikit_build_core:
59+
check_call([pip, "install", "scikit-build-core", "--upgrade"])
60+
else:
61+
check_call([pip, "install", "scikit_build", "--upgrade"])
62+
63+
check_call([pip, "install", "ninja", "--upgrade"])
5464
check_call([pip, "install", "delvewheel"])
5565

56-
build_type = "Release"
5766
source_path = ROOT_DIR
5867
itk_build_path = os.path.abspath("%s/ITK-win_%s" % (os.path.join(SCRIPT_DIR, '..'), py_env))
5968
print('ITKDIR: %s' % itk_build_path)
6069

61-
# Generate wheel
62-
check_call([
63-
python_executable,
64-
"setup.py", "bdist_wheel",
65-
"--build-type", build_type, "-G", "Ninja",
66-
"--",
67-
"-DCMAKE_MAKE_PROGRAM:FILEPATH=%s" % ninja_executable,
68-
"-DITK_DIR:PATH=%s" % itk_build_path,
69-
"-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel",
70-
"-DSWIG_EXECUTABLE:FILEPATH=%s/Wrapping/Generators/SwigInterface/swig/bin/swig.exe" % itk_build_path,
71-
"-DBUILD_TESTING:BOOL=OFF",
72-
"-DCMAKE_INSTALL_LIBDIR:STRING=lib",
73-
"-DPython3_EXECUTABLE:FILEPATH=%s" % python_executable,
74-
"-DPython3_INCLUDE_DIR:PATH=%s" % python_include_dir,
75-
"-DPython3_INCLUDE_DIRS:PATH=%s" % python_include_dir,
76-
"-DPython3_LIBRARY:FILEPATH=%s" % python_library
77-
] + cmake_options)
78-
# Cleanup
79-
if cleanup:
80-
check_call([python_executable, "setup.py", "clean"])
70+
if use_scikit_build_core:
71+
minor_version = py_env.split("-")[0][1:]
72+
if int(minor_version) >= 11:
73+
# Stable ABI
74+
wheel_py_api = "cp3%s" % minor_version
75+
else:
76+
wheel_py_api = ""
77+
# Generate wheel
78+
check_call([
79+
python_executable,
80+
"-m", "pip",
81+
"--verbose",
82+
"wheel",
83+
"--wheel-dir", "dist",
84+
"--no-deps",
85+
"--config-settings=wheel.py-api=%s" % wheel_py_api,
86+
"--config-settings=cmake.define.SKBUILD:BOOL=ON",
87+
"--config-settings=cmake.define.PY_SITE_PACKAGES_PATH:PATH=.",
88+
"--config-settings=cmake.define.ITK_DIR:PATH=%s" % itk_build_path,
89+
"--config-settings=cmake.define.WRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel",
90+
"--config-settings=cmake.define.SWIG_EXECUTABLE:FILEPATH=%s/Wrapping/Generators/SwigInterface/swig/bin/swig.exe" % itk_build_path,
91+
"--config-settings=cmake.define.BUILD_TESTING:BOOL=OFF",
92+
"--config-settings=cmake.define.CMAKE_INSTALL_LIBDIR:STRING=lib",
93+
"--config-settings=cmake.define.Python3_EXECUTABLE:FILEPATH=%s" % python_executable,
94+
"--config-settings=cmake.define.Python3_INCLUDE_DIR:PATH=%s" % python_include_dir,
95+
"--config-settings=cmake.define.Python3_INCLUDE_DIRS:PATH=%s" % python_include_dir,
96+
"--config-settings=cmake.define.Python3_LIBRARY:FILEPATH=%s" % python_library,
97+
"--config-settings=cmake.define.Python3_SABI_LIBRARY:FILEPATH=%s" % python_library,
98+
] + [o.replace('-D', '--config-settings=cmake.define.') for o in cmake_options] + ['.',])
99+
else:
100+
# scikit-build classic
101+
build_type = "Release"
102+
103+
# Generate wheel
104+
check_call([
105+
python_executable,
106+
"setup.py", "bdist_wheel",
107+
"--build-type", build_type, "-G", "Ninja",
108+
"--",
109+
"-DCMAKE_MAKE_PROGRAM:FILEPATH=%s" % ninja_executable,
110+
"-DITK_DIR:PATH=%s" % itk_build_path,
111+
"-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel",
112+
"-DSWIG_EXECUTABLE:FILEPATH=%s/Wrapping/Generators/SwigInterface/swig/bin/swig.exe" % itk_build_path,
113+
"-DBUILD_TESTING:BOOL=OFF",
114+
"-DCMAKE_INSTALL_LIBDIR:STRING=lib",
115+
"-DPython3_EXECUTABLE:FILEPATH=%s" % python_executable,
116+
"-DPython3_INCLUDE_DIR:PATH=%s" % python_include_dir,
117+
"-DPython3_INCLUDE_DIRS:PATH=%s" % python_include_dir,
118+
"-DPython3_LIBRARY:FILEPATH=%s" % python_library
119+
] + cmake_options)
120+
# Cleanup
121+
if cleanup:
122+
check_call([python_executable, "setup.py", "clean"])
81123

82124
def rename_wheel_init(py_env, filepath):
83125
"""

0 commit comments

Comments
 (0)