1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
From da0e9240bf6505ac3a67ff985705950566c66144 Mon Sep 17 00:00:00 2001
From: Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>
Date: Thu, 21 Dec 2023 12:01:50 +0200
Subject: 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 <ilmari.lauhakangas@libreoffice.org>
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>
---
pyuno/source/loader/pyuno_loader.cxx | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/pyuno/source/loader/pyuno_loader.cxx b/pyuno/source/loader/pyuno_loader.cxx
index 008d58634947..1e00773761e7 100644
--- a/pyuno/source/loader/pyuno_loader.cxx
+++ b/pyuno/source/loader/pyuno_loader.cxx
@@ -114,7 +114,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) );
@@ -138,9 +142,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 )
@@ -192,11 +198,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 );
@@ -205,7 +217,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 );
--
cgit v1.2.3
|