Embedded python package (zip) for Linux (#871)

Signed-off-by: Paulchen-Panther <Paulchen-Panter@protonmail.com>
This commit is contained in:
Paulchen Panther
2020-07-12 09:26:28 +02:00
committed by GitHub
parent c32a4df587
commit 8c188d71d9
2 changed files with 76 additions and 51 deletions

View File

@@ -17,29 +17,28 @@
#ifdef _WIN32
#include <stdexcept>
#define STRINGIFY2(x) #x
#define STRINGIFY(x) STRINGIFY2(x)
#endif
#define STRINGIFY2(x) #x
#define STRINGIFY(x) STRINGIFY2(x)
PythonInit::PythonInit()
{
// register modules
EffectModule::registerHyperionExtensionModule();
// set Python module path when exists
wchar_t *pythonPath = nullptr;
#ifdef _WIN32
pythonPath = Py_DecodeLocale((QDir::cleanPath(qApp->applicationDirPath()) + "/python" + STRINGIFY(PYTHON_VERSION_MAJOR_MINOR) + ".zip").toLatin1().data(), nullptr);
if(QFile(QString::fromWCharArray(pythonPath)).exists())
#else
pythonPath = Py_DecodeLocale((QDir::cleanPath(qApp->applicationDirPath() + "/../lib/python")).toLatin1().data(), nullptr);
if(QDir(QString::fromWCharArray(pythonPath)).exists())
#endif
QString py_patch = QDir::cleanPath(qApp->applicationDirPath() + "/../lib/python");
QString py_file = QDir::cleanPath(qApp->applicationDirPath() + "/python" + STRINGIFY(PYTHON_VERSION_MAJOR_MINOR) + ".zip");
if (QFile(py_file).exists() || QDir(py_patch).exists())
{
Py_NoSiteFlag++;
Py_SetPath(pythonPath);
PyMem_RawFree(pythonPath);
if (QFile(py_file).exists())
Py_SetPath(Py_DecodeLocale(py_file.toLatin1().data(), nullptr));
else if (QDir(py_patch).exists())
Py_SetPath(Py_DecodeLocale(py_patch.toLatin1().data(), nullptr));
}
// init Python