From a19fef224802deca1b8775b4f67453b6d4e56869 Mon Sep 17 00:00:00 2001 From: Rat <52238970+ratwithacompiler@users.noreply.github.com> Date: Sun, 17 Nov 2019 22:11:44 +0100 Subject: [PATCH] obs-scripting: Fix Python in new MacOS .app bundles The current scripting directory path given to Python on OSX is `../data/obs-scripting`. This works when bin/ and data/ are in the same folder like rundir after a compile and in the old .app bundles but the new normal .app bundle structure is different. For bundles move obspython.py and _obspython.so to the binary folder, just like the Lua one, and pass that bin path to the Python interpreter so it can find it. The current working dir isn't guaranteed to be set with .app bundles so look up binary path at runtime. --- CI/before-deploy-osx.sh | 6 +++--- CI/install/osx/packageApp.sh | 1 + deps/obs-scripting/obs-scripting-python.c | 7 +++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CI/before-deploy-osx.sh b/CI/before-deploy-osx.sh index fa84613e7..7c092c420 100755 --- a/CI/before-deploy-osx.sh +++ b/CI/before-deploy-osx.sh @@ -22,9 +22,9 @@ hr "Moving OBS LUA" mv ./rundir/RelWithDebInfo/data/obs-scripting/obslua.so ./rundir/RelWithDebInfo/bin/ # Move obspython -# hr "Moving OBS Python" -# mv ./rundir/RelWithDebInfo/data/obs-scripting/_obspython.so ./rundir/RelWithDebInfo/bin/ -# mv ./rundir/RelWithDebInfo/data/obs-scripting/obspython.py ./rundir/RelWithDebInfo/bin/ +hr "Moving OBS Python" +mv ./rundir/RelWithDebInfo/data/obs-scripting/_obspython.so ./rundir/RelWithDebInfo/bin/ +mv ./rundir/RelWithDebInfo/data/obs-scripting/obspython.py ./rundir/RelWithDebInfo/bin/ # Package everything into a nice .app hr "Packaging .app" diff --git a/CI/install/osx/packageApp.sh b/CI/install/osx/packageApp.sh index ec19c1ce5..e3175b995 100755 --- a/CI/install/osx/packageApp.sh +++ b/CI/install/osx/packageApp.sh @@ -35,6 +35,7 @@ cp ../CI/install/osx/Info.plist ./OBS.app/Contents -x ./OBS.app/Contents/MacOS/obs \ -x ./OBS.app/Contents/MacOS/obs-ffmpeg-mux \ -x ./OBS.app/Contents/MacOS/obslua.so \ +-x ./OBS.app/Contents/MacOS/_obspython.so \ -x ./OBS.app/Contents/Plugins/obs-x264.so \ -x ./OBS.app/Contents/Plugins/text-freetype2.so \ -x ./OBS.app/Contents/Plugins/obs-libfdk.so diff --git a/deps/obs-scripting/obs-scripting-python.c b/deps/obs-scripting/obs-scripting-python.c index d02ac8087..8899df816 100644 --- a/deps/obs-scripting/obs-scripting-python.c +++ b/deps/obs-scripting/obs-scripting-python.c @@ -1651,6 +1651,13 @@ bool obs_scripting_load_python(const char *python_path) add_to_python_path(SCRIPT_DIR); +#if __APPLE__ + char *exec_path = os_get_executable_path_ptr(""); + if (exec_path) + add_to_python_path(exec_path); + bfree(exec_path); +#endif + py_obspython = PyImport_ImportModule("obspython"); bool success = !py_error(); if (!success) {