@@ -119,7 +119,7 @@ def prepare_build_env(python_version):
119119 pip_install (venv_dir , "scikit-build" )
120120
121121
122- def build_wheel (python_version ):
122+ def build_wheel (python_version , single_wheel = False ):
123123 venv_dir = os .path .join (ROOT_DIR , "venv-%s" % python_version )
124124
125125 python_executable = os .path .join (venv_dir , "Scripts" , "python.exe" )
@@ -144,28 +144,103 @@ def build_wheel(python_version):
144144 # Update PATH
145145 path = os .path .join (venv_dir , "Scripts" )
146146 with push_env (PATH = "%s:%s" % (path , os .environ ["PATH" ])):
147+
148+ # Install dependencies
147149 check_call ([pip , "install" ,
148150 "-r" , os .path .join (ROOT_DIR , "requirements-dev.txt" )])
149151
152+ build_type = "Release"
153+ source_path = "%s/ITK-source" % STANDALONE_DIR
150154 build_path = "C:/P/IPP/ITK-win_%s" % python_version
155+ setup_py_configure = os .path .join (
156+ SCRIPT_DIR , ".." , "setup_py_configure.py" )
151157
152158 # Clean up previous invocations
153159 if os .path .exists (build_path ):
154160 shutil .rmtree (build_path )
155161
156- check_call ([
157- python_executable ,
158- "setup.py" , "bdist_wheel" , "--build-type" , "Release" , "-G" , "Ninja" ,
159- "--" ,
160- "-DCMAKE_MAKE_PROGRAM:FILEPATH=%s" % ninja_executable ,
161- "-DITK_SOURCE_DIR:PATH=%s/ITK-source" % STANDALONE_DIR ,
162- "-DITK_BINARY_DIR:PATH=%s" % build_path ,
163- "-DPYTHON_EXECUTABLE:FILEPATH=%s" % python_executable ,
164- "-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir ,
165- "-DPYTHON_LIBRARY:FILEPATH=%s" % python_library
166- ])
167-
168- check_call ([python_executable , "setup.py" , "clean" ])
162+ if single_wheel :
163+
164+ print ("#" )
165+ print ("# Build single ITK wheel" )
166+ print ("#" )
167+
168+ # Configure setup.py
169+ check_call ([python_executable , setup_py_configure , "itk" ])
170+
171+ # Generate wheel
172+ check_call ([
173+ python_executable ,
174+ "setup.py" , "bdist_wheel" ,
175+ "--build-type" , build_type , "-G" , "Ninja" ,
176+ "--" ,
177+ "-DCMAKE_MAKE_PROGRAM:FILEPATH=%s" % ninja_executable ,
178+ "-DITK_SOURCE_DIR:PATH=%s" % source_path ,
179+ "-DITK_BINARY_DIR:PATH=%s" % build_path ,
180+ "-DPYTHON_EXECUTABLE:FILEPATH=%s" % python_executable ,
181+ "-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir ,
182+ "-DPYTHON_LIBRARY:FILEPATH=%s" % python_library
183+ ])
184+ # Cleanup
185+ check_call ([python_executable , "setup.py" , "clean" ])
186+
187+ else :
188+
189+ print ("#" )
190+ print ("# Build multiple ITK wheels" )
191+ print ("#" )
192+
193+ py_site_packages_path = os .path .join (
194+ SCRIPT_DIR , ".." , "_skbuild" , "cmake-install" )
195+
196+ # Build ITK python
197+ with push_dir (directory = build_path , make_directory = True ):
198+ check_call ([
199+ "cmake" ,
200+ "-DCMAKE_BUILD_TYPE:STRING=%s" % build_type ,
201+ "-DITK_SOURCE_DIR:PATH=%s" % source_path ,
202+ "-DITK_BINARY_DIR:PATH=%s" % build_path ,
203+ "-DBUILD_TESTING:BOOL=OFF" ,
204+ "-DPYTHON_EXECUTABLE:FILEPATH=%s" % python_executable ,
205+ "-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir ,
206+ "-DPYTHON_LIBRARY:FILEPATH=%s" % python_library ,
207+ "-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel" ,
208+ "-DWRAP_ITK_INSTALL_COMPONENT_PER_MODULE:BOOL=ON" ,
209+ "-DPY_SITE_PACKAGES_PATH:PATH=%s" % py_site_packages_path ,
210+ "-DITK_LEGACY_SILENT:BOOL=ON" ,
211+ "-DITK_WRAP_PYTHON:BOOL=ON" ,
212+ "-DITK_WRAP_PYTHON_LEGACY:BOOL=OFF" ,
213+ "-G" , "Ninja" ,
214+ source_path
215+ ])
216+ check_call ([ninja_executable ])
217+
218+ # Build wheels
219+ with open (os .path .join (SCRIPT_DIR , ".." , "WHEEL_NAMES.txt" ), "r" ) as content :
220+ wheel_names = content .readline ()
221+
222+ for wheel_name in wheel_names :
223+ # Configure setup.py
224+ check_call ([
225+ python_executable , setup_py_configure , wheel_name ])
226+
227+ # Generate wheel
228+ check_call ([
229+ python_executable ,
230+ "setup.py" , "bdist_wheel" ,
231+ "--build-type" , build_type , "-G" , "Ninja" ,
232+ "--" ,
233+ "-DITK_SOURCE_DIR:PATH=%s" % source_path ,
234+ "-DITK_BINARY_DIR:PATH=%s" % build_path ,
235+ "-DITKPythonPackage_ITK_BINARY_REUSE:BOOL=ON" ,
236+ "-DITKPythonPackage_WHEEL_NAME:STRING=%s" % wheel_name ,
237+ "-DPYTHON_EXECUTABLE:FILEPATH=%s" % python_executable ,
238+ "-DPYTHON_INCLUDE_DIR:PATH=%s" % python_include_dir ,
239+ "-DPYTHON_LIBRARY:FILEPATH=%s" % python_library
240+ ])
241+
242+ # Cleanup
243+ check_call ([python_executable , "setup.py" , "clean" ])
169244
170245 # Remove unnecessary files for building against ITK
171246 for root , _ , file_list in os .walk (build_path ):
@@ -192,6 +267,7 @@ def build_wheels():
192267 pip_install (tools_venv , "ninja" )
193268 ninja_executable = os .path .join (tools_venv , "Scripts" , "ninja.exe" )
194269
270+ # Build standalone project and populate archive cache
195271 check_call ([
196272 cmake_executable ,
197273 "-DITKPythonPackage_BUILD_PYTHON:PATH=0" ,
@@ -202,10 +278,12 @@ def build_wheels():
202278
203279 check_call ([ninja_executable ])
204280
281+ single_wheel = False
282+
205283 # Compile wheels re-using standalone project and archive cache
206- build_wheel ("27-x64" )
207- build_wheel ("35-x64" )
208- build_wheel ("36-x64" )
284+ build_wheel ("27-x64" , single_wheel = single_wheel )
285+ build_wheel ("35-x64" , single_wheel = single_wheel )
286+ build_wheel ("36-x64" , single_wheel = single_wheel )
209287
210288
211289if __name__ == "__main__" :
0 commit comments