@@ -160,27 +160,74 @@ endif()
160160add_compile_definitions (SHAPEWORKS_BUNDLED_PYTHON_SOURCE_DIR = "${CMAKE_SOURCE_DIR} /Python" )
161161add_compile_definitions (SHAPEWORKS_BUNDLED_PYTHON_CONDA_PREFIX= "${_conda_prefix} " )
162162
163+ # ---------------------------------------------------------------------------
164+ # In-source ShapeWorks Python packages — editable-installed into the bundled
165+ # Python so 'swpython RunUseCase.py' against a source build picks up edits to
166+ # Python/shapeworks etc. without rebuilding. The install rules copy these
167+ # directories in separately for the deployed bundle.
168+ # ---------------------------------------------------------------------------
169+ set (_sw_editable_packages
170+ "${CMAKE_SOURCE_DIR} /Python/shapeworks"
171+ "${CMAKE_SOURCE_DIR} /Python/DataAugmentationUtilsPackage"
172+ "${CMAKE_SOURCE_DIR} /Python/DatasetUtilsPackage"
173+ "${CMAKE_SOURCE_DIR} /Python/DeepSSMUtilsPackage"
174+ "${CMAKE_SOURCE_DIR} /Python/DocumentationUtilsPackage"
175+ "${CMAKE_SOURCE_DIR} /Python/ShapeCohortGenPackage"
176+ )
177+
163178# ---------------------------------------------------------------------------
164179# Custom target: install pip packages into the bundled Python
165180# ---------------------------------------------------------------------------
166181if (WIN32 )
167182 # On Windows GHA runners, pip's platformdirs crashes trying to read
168183 # CSIDL_COMMON_APPDATA from the registry. The --isolated flag skips
169184 # all config file and environment variable processing.
170- add_custom_target (bundled_pip_install
171- COMMAND "${BUNDLED_PYTHON_EXECUTABLE} " -m pip install --isolated --upgrade pip
172- COMMAND "${BUNDLED_PYTHON_EXECUTABLE} " -m pip install --isolated -r "${CMAKE_SOURCE_DIR} /python_requirements_bundled.txt"
173- COMMENT "Installing runtime pip packages into bundled Python"
174- VERBATIM
175- )
185+ set (_pip_flags --isolated)
176186else ()
177- add_custom_target (bundled_pip_install
178- COMMAND "${BUNDLED_PYTHON_EXECUTABLE} " -m pip install --upgrade pip
179- COMMAND "${BUNDLED_PYTHON_EXECUTABLE} " -m pip install -r "${CMAKE_SOURCE_DIR} /python_requirements_bundled.txt"
180- COMMENT "Installing runtime pip packages into bundled Python"
181- VERBATIM
182- )
187+ set (_pip_flags "" )
188+ endif ()
189+
190+ add_custom_target (bundled_pip_install
191+ COMMAND "${BUNDLED_PYTHON_EXECUTABLE} " -m pip install ${_pip_flags} --upgrade pip
192+ COMMAND "${BUNDLED_PYTHON_EXECUTABLE} " -m pip install ${_pip_flags} -r "${CMAKE_SOURCE_DIR} /python_requirements_bundled.txt"
193+ COMMENT "Installing runtime pip packages into bundled Python"
194+ VERBATIM
195+ )
196+
197+ foreach (_pkg ${_sw_editable_packages} )
198+ if (EXISTS "${_pkg} /setup.py" )
199+ add_custom_command (TARGET bundled_pip_install POST_BUILD
200+ COMMAND "${BUNDLED_PYTHON_EXECUTABLE} " -m pip install ${_pip_flags} --no-deps -e "${_pkg} "
201+ COMMENT "Editable-installing ${_pkg} into bundled Python"
202+ VERBATIM
203+ )
204+ endif ()
205+ endforeach ()
206+
207+ # ---------------------------------------------------------------------------
208+ # Build-tree swpython wrapper — points at the bundled python in the build dir
209+ # and puts CMAKE_RUNTIME_OUTPUT_DIRECTORY on PYTHONPATH so shapeworks_py.so is
210+ # importable. The install-tree variant is generated in InstallBundledPython.cmake.
211+ # ---------------------------------------------------------------------------
212+ if (WIN32 )
213+ set (_dev_wrapper "${CMAKE_BINARY_DIR} /bin/swpython.bat" )
214+ file (WRITE "${_dev_wrapper} "
215+ "@echo off
216+ set \" PYTHONHOME=${BUNDLED_PYTHON_ROOT} \"
217+ set \" PYTHONPATH=${CMAKE_BINARY_DIR} /bin\"
218+ \" ${BUNDLED_PYTHON_EXECUTABLE} \" %*
219+ " )
220+ else ()
221+ set (_dev_wrapper "${CMAKE_BINARY_DIR} /bin/swpython" )
222+ file (WRITE "${_dev_wrapper} "
223+ "#!/bin/bash
224+ export PYTHONHOME='${BUNDLED_PYTHON_ROOT} '
225+ export PYTHONPATH='${CMAKE_BINARY_DIR} /bin'
226+ exec '${BUNDLED_PYTHON_EXECUTABLE} ' \"\$ @\"
227+ " )
228+ execute_process (COMMAND chmod 755 "${_dev_wrapper} " )
183229endif ()
230+ message (STATUS "Build-tree swpython wrapper: ${_dev_wrapper} " )
184231
185232message (STATUS "Bundled Python root: ${BUNDLED_PYTHON_ROOT} " )
186233message (STATUS "Bundled Python executable: ${BUNDLED_PYTHON_EXECUTABLE} " )
0 commit comments