commit:     1f0c1e26a740bfb079a9f6bd1ee65a047f29a4f7
Author:     Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 12 15:14:14 2024 +0000
Commit:     Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
CommitDate: Wed Jun 12 15:14:14 2024 +0000
URL:        https://gitweb.gentoo.org/proj/kde.git/commit/?id=1f0c1e26

dev-util/kdevelop-python: enable py3.12

Closes: https://bugs.gentoo.org/929546
Signed-off-by: Andreas Sturmlechner <asturm <AT> gentoo.org>

 .../files/kdevelop-python-24.05.1-python3.12.patch | 190 +++++++++++++++++++++
 .../kdevelop-python/kdevelop-python-24.05.1.ebuild |   4 +-
 .../kdevelop-python-24.05.49.9999.ebuild           |   4 +-
 .../kdevelop-python/kdevelop-python-9999.ebuild    |   2 +-
 4 files changed, 197 insertions(+), 3 deletions(-)

diff --git 
a/dev-util/kdevelop-python/files/kdevelop-python-24.05.1-python3.12.patch 
b/dev-util/kdevelop-python/files/kdevelop-python-24.05.1-python3.12.patch
new file mode 100644
index 0000000000..00507fc0de
--- /dev/null
+++ b/dev-util/kdevelop-python/files/kdevelop-python-24.05.1-python3.12.patch
@@ -0,0 +1,190 @@
+From 26ee370982e7cd7795921e9533b61a5a89d11b6a Mon Sep 17 00:00:00 2001
+From: Bernd Buschinski <b.buschin...@googlemail.com>
+Date: Sat, 8 Jun 2024 16:50:47 +0200
+Subject: [PATCH] initial support for python 3.12
+
+---
+ CMakeLists.txt                  |  2 +-
+ duchain/tests/pyduchaintest.cpp |  5 +++++
+ parser/ast.cpp                  |  3 +++
+ parser/ast.h                    |  6 ++++++
+ parser/astbuilder.cpp           | 15 +++++++++++++--
+ parser/asttransformer.cpp       |  6 ++++++
+ parser/astvisitor.cpp           |  1 +
+ parser/python_grammar.h         | 15 +++++++++++++++
+ 8 files changed, 50 insertions(+), 3 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 9fba20c3..29b83950 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -43,7 +43,7 @@ add_definitions( -DTRANSLATION_DOMAIN=\"kdevpython\" )
+ 
+ set(Python3_USE_STATIC_LIBS FALSE)
+ set(Python3_FIND_STRATEGY VERSION)
+-find_package(Python3 3.4.3...<3.12 COMPONENTS Interpreter Development 
REQUIRED)
++find_package(Python3 3.4.3...<3.13 COMPONENTS Interpreter Development 
REQUIRED)
+ 
+ configure_file(kdevpythonversion.h.cmake 
"${CMAKE_CURRENT_BINARY_DIR}/kdevpythonversion.h" @ONLY)
+ 
+diff --git a/duchain/tests/pyduchaintest.cpp b/duchain/tests/pyduchaintest.cpp
+index b0711fd0..8a4a75e4 100644
+--- a/duchain/tests/pyduchaintest.cpp
++++ b/duchain/tests/pyduchaintest.cpp
+@@ -439,6 +439,11 @@ void PyDUChainTest::testCrashes_data() {
+ #if PYTHON_VERSION >= QT_VERSION_CHECK(3, 11, 0)
+     QTest::newRow("except_star") << "try: pass\nexcept* (IndexError, 
ValueError): pass";
+ #endif
++#if PYTHON_VERSION >= QT_VERSION_CHECK(3, 12, 0)
++    QTest::newRow("type_alias") << "type Point = tuple[float, float]";
++    QTest::newRow("generic_function") << "def func[T](arg: T): pass";
++    QTest::newRow("generic_class") << "class Bag[T]: pass";
++#endif
+ }
+ 
+ void PyDUChainTest::testClassVariables()
+diff --git a/parser/ast.cpp b/parser/ast.cpp
+index a63ac231..4a371b10 100644
+--- a/parser/ast.cpp
++++ b/parser/ast.cpp
+@@ -765,6 +765,9 @@ QString TryAst::dump() const
+     return r;
+ }
+ 
++TypeAliasAst::TypeAliasAst(Ast* parent): StatementAst(parent, 
Ast::TypeAliasType)
++{
++}
+ 
+ WhileAst::WhileAst(Ast* parent): StatementAst(parent, Ast::WhileAstType), 
condition(nullptr)
+ {
+diff --git a/parser/ast.h b/parser/ast.h
+index 430b70d6..acaf79f7 100644
+--- a/parser/ast.h
++++ b/parser/ast.h
+@@ -137,6 +137,7 @@ public:
+         ExceptionHandlerAstType,
+         AliasAstType, // for imports
+         IdentifierAstType,
++        TypeAliasType, // for types
+         LastAstType // the largest one, not valid!
+     };
+     
+@@ -437,6 +438,11 @@ public:
+     QList<Ast*> finally;
+ };
+ 
++class KDEVPYTHONPARSER_EXPORT TypeAliasAst : public StatementAst {
++public:
++    TypeAliasAst(Ast* parent);
++};
++
+ class KDEVPYTHONPARSER_EXPORT ImportAst : public StatementAst {
+ public:
+     ImportAst(Ast* parent);
+diff --git a/parser/astbuilder.cpp b/parser/astbuilder.cpp
+index 9c9ec056..32ab95c7 100644
+--- a/parser/astbuilder.cpp
++++ b/parser/astbuilder.cpp
+@@ -57,7 +57,16 @@ struct PythonParser : private QMutexLocker
+ 
+     PythonParser(QMutex& lock): QMutexLocker(&lock)
+     {
++#if PYTHON_VERSION < QT_VERSION_CHECK(3, 12, 0)
+         Py_InitializeEx(0);
++#else
++        PyConfig config;
++        PyConfig_InitPythonConfig(&config);
++        config.site_import = 0;
++        config.install_signal_handlers = 0;
++        Py_InitializeFromConfig(&config);
++#endif
++
+         Q_ASSERT(Py_IsInitialized());
+         m_parser_mod = PyImport_ImportModule("ast");
+         Q_ASSERT(m_parser_mod); // parser import error
+@@ -92,9 +101,11 @@ struct PythonParser : private QMutexLocker
+ CodeAst::Ptr AstBuilder::parse(const QUrl& filename, QString &contents)
+ {
+     qCDebug(KDEV_PYTHON_PARSER) << " ====> AST     ====>     building 
abstract syntax tree for " << filename.path();
+-    
++
++#if PYTHON_VERSION < QT_VERSION_CHECK(3, 12, 0)
+     Py_NoSiteFlag = 1;
+-    
++#endif
++
+     contents.append('\n');
+     
+     PythonParser py_parser(pyInitLock);
+diff --git a/parser/asttransformer.cpp b/parser/asttransformer.cpp
+index 3884ae13..0c54a498 100644
+--- a/parser/asttransformer.cpp
++++ b/parser/asttransformer.cpp
+@@ -1246,6 +1246,12 @@ Ast* AstTransformer::visitStmtNode(PyObject* node, Ast* 
parent)
+         }
+         result = v;
+     }
++#endif
++#if PYTHON_VERSION >= QT_VERSION_CHECK(3, 12, 0)
++    else if (PyObject_IsInstance(node, grammar.ast_TypeAlias)) {
++        TypeAliasAst* v = new TypeAliasAst(parent);
++        result = v;
++    }
+ #endif
+     else {
+         qWarning() << "Unsupported _stmt AST type: " << 
PyUnicodeObjectToQString(PyObject_Str(node));
+diff --git a/parser/astvisitor.cpp b/parser/astvisitor.cpp
+index eda66000..df21cddf 100644
+--- a/parser/astvisitor.cpp
++++ b/parser/astvisitor.cpp
+@@ -104,6 +104,7 @@ void AstVisitor::visitNode(Ast* node)
+         case Ast::LastStatementType:                            
Q_ASSERT(false); break;
+         case Ast::LastExpressionType:                           
Q_ASSERT(false); break;
+         case Ast::LastPatternType:                              
Q_ASSERT(false); break;
++        case Ast::TypeAliasType:                                break;
+     }
+ }
+ 
+diff --git a/parser/python_grammar.h b/parser/python_grammar.h
+index 1b30be49..88c68f70 100644
+--- a/parser/python_grammar.h
++++ b/parser/python_grammar.h
+@@ -45,6 +45,10 @@ public:
+     PyObject* ast_Pass;
+     PyObject* ast_Break;
+     PyObject* ast_Continue;
++#if PYTHON_VERSION >= QT_VERSION_CHECK(3, 12, 0)
++    // type
++    PyObject* ast_TypeAlias;
++#endif
+ 
+     // expr
+     PyObject* ast_expr;
+@@ -330,6 +334,10 @@ public:
+         Py_GRAMMAR_GET(mod, Bytes);
+ #endif
+ 
++#if PYTHON_VERSION >= QT_VERSION_CHECK(3, 12, 0)
++        Py_GRAMMAR_GET(mod, TypeAlias);
++#endif
++
+         Py_DECREF(mod);
+     }
+ 
+@@ -472,6 +480,13 @@ public:
+         Py_XDECREF(ast_Str);
+         Py_XDECREF(ast_Bytes);
+ #endif
++
++#if PYTHON_VERSION >= QT_VERSION_CHECK(3, 11, 0)
++        Py_XDECREF(ast_TryStar);
++#endif
++#if PYTHON_VERSION >= QT_VERSION_CHECK(3, 12, 0)
++        Py_XDECREF(ast_TypeAlias);
++#endif
+     }
+ };
+ 
+-- 
+GitLab
+

diff --git a/dev-util/kdevelop-python/kdevelop-python-24.05.1.ebuild 
b/dev-util/kdevelop-python/kdevelop-python-24.05.1.ebuild
index ca3cc3e268..5825a13345 100644
--- a/dev-util/kdevelop-python/kdevelop-python-24.05.1.ebuild
+++ b/dev-util/kdevelop-python/kdevelop-python-24.05.1.ebuild
@@ -6,7 +6,7 @@ EAPI=8
 ECM_TEST="forceoptional"
 KDE_ORG_CATEGORY="kdevelop"
 KDE_ORG_NAME="kdev-python"
-PYTHON_COMPAT=( python3_{10..11} )
+PYTHON_COMPAT=( python3_{10..12} )
 KFMIN=5.115.0
 QTMIN=5.15.12
 inherit ecm gear.kde.org python-single-r1
@@ -45,6 +45,8 @@ RDEPEND="${DEPEND}
        ')
 "
 
+PATCHES=( "${FILESDIR}/${P}-python3.12.patch" ) # bug 929546
+
 pkg_setup() {
        python-single-r1_pkg_setup
        ecm_pkg_setup

diff --git a/dev-util/kdevelop-python/kdevelop-python-24.05.49.9999.ebuild 
b/dev-util/kdevelop-python/kdevelop-python-24.05.49.9999.ebuild
index d4369f81db..fa81267383 100644
--- a/dev-util/kdevelop-python/kdevelop-python-24.05.49.9999.ebuild
+++ b/dev-util/kdevelop-python/kdevelop-python-24.05.49.9999.ebuild
@@ -6,7 +6,7 @@ EAPI=8
 ECM_TEST="forceoptional"
 KDE_ORG_CATEGORY="kdevelop"
 KDE_ORG_NAME="kdev-python"
-PYTHON_COMPAT=( python3_{10..11} )
+PYTHON_COMPAT=( python3_{10..12} )
 KFMIN=5.115.0
 QTMIN=5.15.12
 inherit ecm gear.kde.org python-single-r1
@@ -45,6 +45,8 @@ RDEPEND="${DEPEND}
        ')
 "
 
+PATCHES=( "${FILESDIR}/${PN}-24.05.1-python3.12.patch" ) # bug 929546
+
 pkg_setup() {
        python-single-r1_pkg_setup
        ecm_pkg_setup

diff --git a/dev-util/kdevelop-python/kdevelop-python-9999.ebuild 
b/dev-util/kdevelop-python/kdevelop-python-9999.ebuild
index d4369f81db..baf0e1d254 100644
--- a/dev-util/kdevelop-python/kdevelop-python-9999.ebuild
+++ b/dev-util/kdevelop-python/kdevelop-python-9999.ebuild
@@ -6,7 +6,7 @@ EAPI=8
 ECM_TEST="forceoptional"
 KDE_ORG_CATEGORY="kdevelop"
 KDE_ORG_NAME="kdev-python"
-PYTHON_COMPAT=( python3_{10..11} )
+PYTHON_COMPAT=( python3_{10..12} )
 KFMIN=5.115.0
 QTMIN=5.15.12
 inherit ecm gear.kde.org python-single-r1

Reply via email to