Skip to content

Commit e59be7d

Browse files
jcfrthewtex
authored andcommitted
windows_build_wheels: Add build_wrapped_itk function
1 parent 6357946 commit e59be7d

File tree

1 file changed

+67
-53
lines changed

1 file changed

+67
-53
lines changed

scripts/windows_build_wheels.py

Lines changed: 67 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,65 @@ def prepare_build_env(python_version):
122122
pip_install(venv_dir, "scikit-build")
123123

124124

125+
def build_wrapped_itk(
126+
build_type, source_path, build_path,
127+
python_executable, python_include_dir, python_library):
128+
129+
ninja_executable = os.path.join(
130+
ROOT_DIR, "venv-27-x64", "Scripts", "ninja.exe")
131+
print("NINJA_EXECUTABLE:%s" % ninja_executable)
132+
133+
try:
134+
# Because of python issue #14243, we set "delete=False" and
135+
# delete manually after process execution.
136+
script_file = tempfile.NamedTemporaryFile(
137+
delete=False, suffix=".py")
138+
script_file.write(bytearray(textwrap.dedent(
139+
"""
140+
import json
141+
from skbuild.platform_specifics.windows import WindowsPlatform
142+
# Instantiate
143+
build_platform = WindowsPlatform()
144+
generator = build_platform.default_generators[0]
145+
assert generator.name == "Ninja"
146+
print(json.dumps(generator.env))
147+
""" # noqa: E501
148+
), "utf-8"))
149+
script_file.file.flush()
150+
output = check_output([python_executable, script_file.name])
151+
build_env = json.loads(output.decode("utf-8").strip())
152+
finally:
153+
script_file.close()
154+
os.remove(script_file.name)
155+
156+
py_site_packages_path = os.path.join(
157+
SCRIPT_DIR, "..", "_skbuild", "cmake-install")
158+
159+
# Build ITK python
160+
with push_dir(directory=build_path, make_directory=True), \
161+
push_env(**build_env):
162+
163+
check_call([
164+
"cmake",
165+
"-DCMAKE_BUILD_TYPE:STRING=%s" % build_type,
166+
"-DITK_SOURCE_DIR:PATH=%s" % source_path,
167+
"-DITK_BINARY_DIR:PATH=%s" % build_path,
168+
"-DBUILD_TESTING:BOOL=OFF",
169+
"-DPYTHON_EXECUTABLE:FILEPATH=%s" % python_executable,
170+
"-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir,
171+
"-DPYTHON_LIBRARY:FILEPATH=%s" % python_library,
172+
"-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel",
173+
"-DWRAP_ITK_INSTALL_COMPONENT_PER_MODULE:BOOL=ON",
174+
"-DPY_SITE_PACKAGES_PATH:PATH=%s" % py_site_packages_path,
175+
"-DITK_LEGACY_SILENT:BOOL=ON",
176+
"-DITK_WRAP_PYTHON:BOOL=ON",
177+
"-DITK_WRAP_PYTHON_LEGACY:BOOL=OFF",
178+
"-G", "Ninja",
179+
source_path
180+
])
181+
check_call([ninja_executable])
182+
183+
125184
def build_wheel(python_version, single_wheel=False):
126185
venv_dir = os.path.join(ROOT_DIR, "venv-%s" % python_version)
127186

@@ -141,9 +200,6 @@ def build_wheel(python_version, single_wheel=False):
141200

142201
pip = os.path.join(venv_dir, "Scripts", "pip.exe")
143202

144-
ninja_executable = os.path.join(ROOT_DIR, "venv-27-x64", "Scripts", "ninja.exe")
145-
print("NINJA_EXECUTABLE:%s" % ninja_executable)
146-
147203
# Update PATH
148204
path = os.path.join(venv_dir, "Scripts")
149205
with push_env(PATH="%s%s%s" % (path, os.pathsep, os.environ["PATH"])):
@@ -154,7 +210,7 @@ def build_wheel(python_version, single_wheel=False):
154210

155211
build_type = "Release"
156212
source_path = "%s/ITK-source" % STANDALONE_DIR
157-
build_path = "C:/P/IPP/ITK-win_%s" % python_version
213+
build_path = "%s/ITK-win_%s" % (ROOT_DIR, python_version)
158214
setup_py_configure = os.path.join(
159215
SCRIPT_DIR, "..", "setup_py_configure.py")
160216

@@ -171,6 +227,10 @@ def build_wheel(python_version, single_wheel=False):
171227
# Configure setup.py
172228
check_call([python_executable, setup_py_configure, "itk"])
173229

230+
ninja_executable = os.path.join(
231+
ROOT_DIR, "venv-27-x64", "Scripts", "ninja.exe")
232+
print("NINJA_EXECUTABLE:%s" % ninja_executable)
233+
174234
# Generate wheel
175235
check_call([
176236
python_executable,
@@ -193,55 +253,9 @@ def build_wheel(python_version, single_wheel=False):
193253
print("# Build multiple ITK wheels")
194254
print("#")
195255

196-
try:
197-
# Because of python issue #14243, we set "delete=False" and
198-
# delete manually after process execution.
199-
script_file = tempfile.NamedTemporaryFile(
200-
delete=False, suffix=".py")
201-
script_file.write(bytearray(textwrap.dedent(
202-
"""
203-
import json
204-
from skbuild.platform_specifics.windows import WindowsPlatform
205-
# Instantiate
206-
build_platform = WindowsPlatform()
207-
generator = build_platform.default_generators[0]
208-
assert generator.name == "Ninja"
209-
print(json.dumps(generator.env))
210-
""" # noqa: E501
211-
), "utf-8"))
212-
script_file.file.flush()
213-
output = check_output([python_executable, script_file.name])
214-
build_env = json.loads(output.decode("utf-8").strip())
215-
finally:
216-
script_file.close()
217-
os.remove(script_file.name)
218-
219-
py_site_packages_path = os.path.join(
220-
SCRIPT_DIR, "..", "_skbuild", "cmake-install")
221-
222-
# Build ITK python
223-
with push_dir(directory=build_path, make_directory=True), \
224-
push_env(**build_env):
225-
226-
check_call([
227-
"cmake",
228-
"-DCMAKE_BUILD_TYPE:STRING=%s" % build_type,
229-
"-DITK_SOURCE_DIR:PATH=%s" % source_path,
230-
"-DITK_BINARY_DIR:PATH=%s" % build_path,
231-
"-DBUILD_TESTING:BOOL=OFF",
232-
"-DPYTHON_EXECUTABLE:FILEPATH=%s" % python_executable,
233-
"-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir,
234-
"-DPYTHON_LIBRARY:FILEPATH=%s" % python_library,
235-
"-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel",
236-
"-DWRAP_ITK_INSTALL_COMPONENT_PER_MODULE:BOOL=ON",
237-
"-DPY_SITE_PACKAGES_PATH:PATH=%s" % py_site_packages_path,
238-
"-DITK_LEGACY_SILENT:BOOL=ON",
239-
"-DITK_WRAP_PYTHON:BOOL=ON",
240-
"-DITK_WRAP_PYTHON_LEGACY:BOOL=OFF",
241-
"-G", "Ninja",
242-
source_path
243-
])
244-
check_call([ninja_executable])
256+
build_wrapped_itk(
257+
build_type, source_path, build_path,
258+
python_executable, python_include_dir, python_library)
245259

246260
# Build wheels
247261
with open(os.path.join(SCRIPT_DIR, "..", "WHEEL_NAMES.txt"), "r") as content:

0 commit comments

Comments
 (0)