From: Ilmari Lauhakangas Date: Thu, 21 Dec 2023 10:01:50 +0000 (+0200) Subject: tdf#158447 Use PyConfig for setting Python home directory with Python >= 3.8 X-Git-Tag: archive/raspbian/4%24.2.5-1+rpi1~2^2^2~4 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=6fe225dfbceb0bcbc38bb057369dcbd102ff8e43;p=libreoffice.git tdf#158447 Use PyConfig for setting Python home directory with Python >= 3.8 Change-Id: Ic5b7c60613b22f5215cb1a2a13fecf3e0946ca49 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161089 Reviewed-by: Ilmari Lauhakangas Tested-by: Jenkins Reviewed-by: Noel Grandin Tested-by: Ilmari Lauhakangas Gbp-Pq: Name use-PyConfig.diff --- diff --git a/pyuno/source/loader/pyuno_loader.cxx b/pyuno/source/loader/pyuno_loader.cxx index 05a03fe72c4..aea215c1cb0 100644 --- a/pyuno/source/loader/pyuno_loader.cxx +++ b/pyuno/source/loader/pyuno_loader.cxx @@ -105,7 +105,11 @@ static PyRef getObjectFromLoaderModule( const char * func ) return object; } +#if PY_VERSION_HEX >= 0x03080000 +static void setPythonHome ( const OUString & pythonHome, PyConfig * config ) +#else static void setPythonHome ( const OUString & pythonHome ) +#endif { OUString systemPythonHome; osl_getSystemPathFromFileURL( pythonHome.pData, &(systemPythonHome.pData) ); @@ -129,9 +133,11 @@ static void setPythonHome ( const OUString & pythonHome ) PyErr_SetString(PyExc_SystemError, "python home path is too long"); return; } -SAL_WNODEPRECATED_DECLARATIONS_PUSH - Py_SetPythonHome(wide); // deprecated since python 3.11 -SAL_WNODEPRECATED_DECLARATIONS_POP +#if PY_VERSION_HEX >= 0x03080000 + config->home = wide; +#else + Py_SetPythonHome(wide); +#endif } static void prependPythonPath( std::u16string_view pythonPathBootstrap ) @@ -183,11 +189,17 @@ void pythonInit() { if ( Py_IsInitialized()) // may be inited by getComponentContext() already return; +#if PY_VERSION_HEX >= 0x03080000 + PyConfig config; +#endif OUString pythonPath; OUString pythonHome; OUString path( "$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("pythonloader.uno" )); rtl::Bootstrap::expandMacros(path); //TODO: detect failure rtl::Bootstrap bootstrap(path); +#if PY_VERSION_HEX >= 0x03080000 + PyConfig_InitPythonConfig( &config ); +#endif // look for pythonhome bootstrap.getFrom( "PYUNO_LOADER_PYTHONHOME", pythonHome ); @@ -196,7 +208,11 @@ void pythonInit() { // pythonhome+pythonpath must be set before Py_Initialize(), otherwise there appear warning on the console // sadly, there is no api for setting the pythonpath, we have to use the environment variable if( !pythonHome.isEmpty() ) +#if PY_VERSION_HEX >= 0x03080000 + setPythonHome( pythonHome, &config ); +#else setPythonHome( pythonHome ); +#endif if( !pythonPath.isEmpty() ) prependPythonPath( pythonPath );