Skip to content

Commit 8256ab3

Browse files
committed
Add swpython wrapper for the bundled Python interpreter
Installs a 'swpython' launcher at install/bin/ that sets PYTHONHOME to the bundled tree and execs its python3, mirroring ParaView's pvpython. Users can run scripts against the bundled interpreter and pip-install packages without needing conda. Per-platform: bash script on macOS/Linux, .bat on Windows.
1 parent c26edd4 commit 8256ab3

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

cmake/InstallBundledPython.cmake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,48 @@ LOC="`dirname "$0"`"
415415
install(PROGRAMS "${_cli_wrapper_dir}/shapeworks" DESTINATION bin)
416416
endif()
417417

418+
# ---------------------------------------------------------------------------
419+
# 8. Install 'swpython' wrapper that launches the bundled Python with
420+
# PYTHONHOME pointed at the bundled tree. Mirrors ParaView's pvpython:
421+
# swpython my_script.py (run a script against bundled python)
422+
# swpython -m pip install <pkg> (install into bundled site-packages,
423+
# or pass --target for read-only installs)
424+
# ---------------------------------------------------------------------------
425+
set(_swpython_dir "${CMAKE_BINARY_DIR}/_bundled_python/swpython")
426+
file(MAKE_DIRECTORY "${_swpython_dir}")
427+
428+
if(APPLE)
429+
file(WRITE "${_swpython_dir}/swpython"
430+
[=[#!/bin/bash
431+
LOC="`dirname "$0"`"
432+
PYTHONHOME="${LOC}/ShapeWorksStudio.app/Contents/Resources/Python"
433+
unset PYTHONPATH
434+
export PYTHONHOME
435+
exec "${PYTHONHOME}/bin/python3" "$@"
436+
]=])
437+
install(PROGRAMS "${_swpython_dir}/swpython" DESTINATION bin)
438+
439+
elseif(WIN32)
440+
file(WRITE "${_swpython_dir}/swpython.bat"
441+
[=[@echo off
442+
set "LOC=%~dp0"
443+
set "PYTHONHOME=%LOC%..\lib\python"
444+
set "PYTHONPATH="
445+
"%PYTHONHOME%\python.exe" %*
446+
]=])
447+
install(PROGRAMS "${_swpython_dir}/swpython.bat" DESTINATION bin)
448+
449+
else()
450+
# Linux
451+
file(WRITE "${_swpython_dir}/swpython"
452+
[=[#!/bin/bash
453+
LOC="`dirname "$0"`"
454+
PYTHONHOME="${LOC}/../lib/python"
455+
unset PYTHONPATH
456+
export PYTHONHOME
457+
exec "${PYTHONHOME}/bin/python3" "$@"
458+
]=])
459+
install(PROGRAMS "${_swpython_dir}/swpython" DESTINATION bin)
460+
endif()
461+
418462
message(STATUS "InstallBundledPython: will install bundled Python to ${_app_python_dest}")

0 commit comments

Comments
 (0)