Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: fix Py_SetPythonHome deprecated API for newer versions #3322

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/common/PythonManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,23 @@ void PythonManager::initPythonHome()
}
#endif

#if (PY_MAJOR_VERSION <= 3) && (PY_MICRO_VERSION < 11)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the API and ABI versioning documentation, I would suggest the following:

Suggested change
#if (PY_MAJOR_VERSION <= 3) && (PY_MICRO_VERSION < 11)
#if (PY_MAJOR_VERSION == 3) && (PY_MINOR_VERSION < 11)

if (!customPythonHome.isNull()) {
qInfo() << "PYTHONHOME =" << customPythonHome;
pythonHome = Py_DecodeLocale(customPythonHome.toLocal8Bit().constData(), nullptr);

// This function is deprecated starting from Python 3.11
Py_SetPythonHome(pythonHome);
}
#else
PyConfig config;
PyConfig_InitPythonConfig(&config);

if (!customPythonHome.isNull()) {
qInfo() << "PYTHONHOME =" << customPythonHome;
PyConfig_SetBytesString(&config, &config.home, customPythonHome);
}
#endif
}

#ifdef CUTTER_ENABLE_PYTHON_BINDINGS
Expand All @@ -75,11 +87,20 @@ void PythonManager::initialize()
#ifdef CUTTER_ENABLE_PYTHON_BINDINGS
PyImport_AppendInittab("CutterBindings", &PyInit_CutterBindings);
#endif
#if (PY_MAJOR_VERSION <= 3) && (PY_MICRO_VERSION < 11)
Py_Initialize();
#else
Py_InitializeFromConfig(&config);
#endif
// This function is deprecated does nothing starting from Python 3.9
#if (PY_MAJOR_VERSION <= 3) && (PY_MICRO_VERSION < 9)
PyEval_InitThreads();
#endif

#if (PY_MAJOR_VERSION <= 3) && (PY_MICRO_VERSION >= 11)
PyConfig_Clear(&config);
#endif

pyThreadStateCounter = 1; // we have the thread now => 1

RegQtResImporter();
Expand Down
Loading