aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfuzzard <fuzzard@users.noreply.github.com>2023-05-20 17:28:40 +1000
committerGitHub <noreply@github.com>2023-05-20 17:28:40 +1000
commit8471ac5a672b18b7c6e20f5acc8200ff9b0c47fd (patch)
tree1179206f412f794024ae6cb30e0a553a117984d6
parentf71f23da39e7746bfbbee00f1b8c12b3ff7e0363 (diff)
parent54397651f7cb46932de66061b527671412ebb593 (diff)
downloadxbmc-8471ac5a672b18b7c6e20f5acc8200ff9b0c47fd.tar.xz
Merge pull request #23274 from lrusak/Nexus-python-fix-module-order
[backport] CPythonInvoker: fix python path by inserting custom path before default path
-rw-r--r--xbmc/interfaces/python/PythonInvoker.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/xbmc/interfaces/python/PythonInvoker.cpp b/xbmc/interfaces/python/PythonInvoker.cpp
index 55c5181403..1e9d344151 100644
--- a/xbmc/interfaces/python/PythonInvoker.cpp
+++ b/xbmc/interfaces/python/PythonInvoker.cpp
@@ -226,29 +226,30 @@ bool CPythonInvoker::execute(const std::string& script, std::vector<std::wstring
}
PyObject* sysPath = PySys_GetObject("path");
- Py_ssize_t listSize = PyList_Size(sysPath);
- if (listSize > 0)
- CLog::Log(LOGDEBUG, "CPythonInvoker({}): default python path:", GetId());
+ std::for_each(pythonPath.crbegin(), pythonPath.crend(),
+ [&sysPath](const auto& path)
+ {
+ PyObject* pyPath = PyUnicode_FromString(path.c_str());
+ PyList_Insert(sysPath, 0, pyPath);
- for (Py_ssize_t index = 0; index < listSize; index++)
- {
- PyObject* pyPath = PyList_GetItem(sysPath, index);
+ Py_DECREF(pyPath);
+ });
- CLog::Log(LOGDEBUG, "CPythonInvoker({}): {}", GetId(), PyUnicode_AsUTF8(pyPath));
- }
+ CLog::Log(LOGDEBUG, "CPythonInvoker({}): full python path:", GetId());
- if (!pythonPath.empty())
- CLog::Log(LOGDEBUG, "CPythonInvoker({}): adding path:", GetId());
+ Py_ssize_t pathListSize = PyList_Size(sysPath);
- for (const auto& path : pythonPath)
+ for (Py_ssize_t index = 0; index < pathListSize; index++)
{
- PyObject* pyPath = PyUnicode_FromString(path.c_str());
- PyList_Append(sysPath, pyPath);
+ if (index == 0 && !pythonPath.empty())
+ CLog::Log(LOGDEBUG, "CPythonInvoker({}): custom python path:", GetId());
- CLog::Log(LOGDEBUG, "CPythonInvoker({}): {}", GetId(), PyUnicode_AsUTF8(pyPath));
+ if (index == static_cast<ssize_t>(pythonPath.size()))
+ CLog::Log(LOGDEBUG, "CPythonInvoker({}): default python path:", GetId());
- Py_DECREF(pyPath);
+ PyObject* pyPath = PyList_GetItem(sysPath, index);
+ CLog::Log(LOGDEBUG, "CPythonInvoker({}): {}", GetId(), PyUnicode_AsUTF8(pyPath));
}
{ // set the m_threadState to this new interp