Skip to content

Commit

Permalink
media-gfx/krita: enable py3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
a17r committed Nov 25, 2024
1 parent 8eb1162 commit 96a63e8
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 1 deletion.
120 changes: 120 additions & 0 deletions media-gfx/krita/files/krita-5.2.6-py3.13.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
From 0f43ec3158225092f6a02422eb90c56421326570 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Robert-Andr=C3=A9=20Mauchin?= <[email protected]>
Date: Tue, 18 Jun 2024 22:05:34 +0200
Subject: [PATCH] Changes to build pykrita with Python 3.13

Python 3.11 deprecated Py_SetPath() in 2022 and Python 3.13 removed it.
Instead one needs to use the new PyConfig API (PEP 587) added to Python
3.8.

Fix: #488680
---
.../extensions/pykrita/plugin/utilities.cpp | 61 +++++++++++++++++--
plugins/extensions/pykrita/plugin/utilities.h | 4 +-
2 files changed, 57 insertions(+), 8 deletions(-)

diff --git a/plugins/extensions/pykrita/plugin/utilities.cpp b/plugins/extensions/pykrita/plugin/utilities.cpp
index 4f58183238..1e497b2681 100644
--- a/plugins/extensions/pykrita/plugin/utilities.cpp
+++ b/plugins/extensions/pykrita/plugin/utilities.cpp
@@ -19,8 +19,10 @@
#include <cmath>
#include <Python.h>

+#include <QDebug>
#include <QDir>
#include <QLibrary>
+#include <QProcessEnvironment>
#include <QString>
#include <QStringList>
#include <QVector>
@@ -412,18 +414,65 @@ bool Python::setPath(const QStringList& scriptPaths)
joinedPaths = joinedPaths + pathSeparator + originalPath;
}
dbgScript << "Setting python paths:" << joinedPaths;
+
#ifdef Q_OS_WIN
- QVector<wchar_t> joinedPathsWChars(joinedPaths.size() + 1, 0);
- joinedPaths.toWCharArray(joinedPathsWChars.data());
- Py_SetPath(joinedPathsWChars.data());
+ PyStatus status;
+ PyConfig config;
+ PyConfig_InitPythonConfig(&config);
+
+ for (const QString& path : joinedPaths.split(pathSeparator)) {
+ status = PyWideStringList_Append(&config.module_search_paths, path.toStdWString().c_str());
+ if (PyStatus_Exception(status)) {
+ qDebug() << "Error appending to PyWideStringList:" << status.err_msg;
+ dbgScript << "Error appending to PyWideStringList";
+ return false;
+ }
+ }
+
+ config.module_search_paths_set = true;
+ qDebug() << "Set module_search_paths";
+
+ status = Py_InitializeFromConfig(&config);
+ if (PyStatus_Exception(status)) {
+ qDebug() << "Cannot initialize Py_InitializeFromConfig:" << status.err_msg;
+ Py_ExitStatusException(status);
+ PyConfig_Clear(&config);
+ dbgScript << "Cannot initialize Py_InitializeFromConfig config";
+ return false;
+ }
+
+ PyConfig_Clear(&config);
#else
if (runningInBundle) {
- QVector<wchar_t> joinedPathsWChars(joinedPaths.size() + 1, 0);
- joinedPaths.toWCharArray(joinedPathsWChars.data());
- Py_SetPath(joinedPathsWChars.data());
+ PyStatus status;
+ PyConfig config;
+ PyConfig_InitPythonConfig(&config);
+
+ for (const QString& path : joinedPaths.split(pathSeparator)) {
+ status = PyWideStringList_Append(&config.module_search_paths, path.toStdWString().c_str());
+ if (PyStatus_Exception(status)) {
+ qDebug() << "Error appending to PyWideStringList:" << status.err_msg;
+ dbgScript << "Error appending to PyWideStringList";
+ return false;
+ }
+ }
+
+ config.module_search_paths_set = true;
+
+ status = Py_InitializeFromConfig(&config);
+ if (PyStatus_Exception(status)) {
+ Py_ExitStatusException(status);
+ qDebug() << "Cannot initialize Py_InitializeFromConfig 2:" << status.err_msg;
+ PyConfig_Clear(&config);
+ dbgScript << "Cannot initialize Py_InitializeFromConfig config";
+ return false;
+ }
+
+ PyConfig_Clear(&config);
}
else {
qputenv("PYTHONPATH", joinedPaths.toLocal8Bit());
+ qDebug() << "Set PYTHONPATH environment variable";
}
#endif
isPythonPathSet = true;
diff --git a/plugins/extensions/pykrita/plugin/utilities.h b/plugins/extensions/pykrita/plugin/utilities.h
index fb309bd0b8..aec47da239 100644
--- a/plugins/extensions/pykrita/plugin/utilities.h
+++ b/plugins/extensions/pykrita/plugin/utilities.h
@@ -81,8 +81,8 @@ public:
static bool libraryLoad();

/**
- * Set the Python paths by calling Py_SetPath. This should be called before
- * initialization to ensure the proper libraries get loaded.
+ * Set the Python paths by calling Py_InitializeFromConfig. This should be
+ * called before initialization to ensure the proper libraries get loaded.
*/
static bool setPath(const QStringList& scriptPaths);

--
2.45.2

4 changes: 3 additions & 1 deletion media-gfx/krita/krita-9999.ebuild
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
EAPI=8

ECM_TEST="forceoptional"
PYTHON_COMPAT=( python3_{10..12} )
PYTHON_COMPAT=( python3_{10..13} )
KFMIN=5.115.0
QTMIN=5.15.12
inherit ecm kde.org python-single-r1
Expand Down Expand Up @@ -96,6 +96,8 @@ PATCHES=(
# downstream
"${FILESDIR}"/${PN}-5.2.3-tests-optional.patch
"${FILESDIR}"/${PN}-5.2.2-fftw.patch # bug 913518
# Fedora, non-upstreamed:
"${FILESDIR}"/${P}-py3.13.patch # bug 943149
)

pkg_setup() {
Expand Down

0 comments on commit 96a63e8

Please sign in to comment.