libmraa: add Python 3.13 compatibility
authorTianling Shen <[email protected]>
Mon, 17 Nov 2025 12:54:43 +0000 (20:54 +0800)
committerTianling Shen <[email protected]>
Fri, 21 Nov 2025 10:11:18 +0000 (18:11 +0800)
Upstream backport.

Add python-setuptools/host as build dependency to fix libmraa-python3
build.

Signed-off-by: Tianling Shen <[email protected]>
libs/libmraa/Makefile
libs/libmraa/patches/003-python-binding-Fix-Python-3-13-compatibility.patch [new file with mode: 0644]

index 2f18f9329f83afd6af6690ea70094c5c24ad9d99..678c11c019192607125a118674389f0498f0519f 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=libmraa
 PKG_VERSION:=2.2.0
-PKG_RELEASE:=3
+PKG_RELEASE:=4
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=https://codeload.github.com/eclipse/mraa/tar.gz/v$(PKG_VERSION)?
@@ -20,7 +20,7 @@ PKG_MAINTAINER:=John Crispin <[email protected]>, Hirokazu MORIKAWA <morikw2@gm
 PKG_LICENSE:=MIT
 PKG_LICENSE_FILES:=COPYING
 
-PKG_BUILD_DEPENDS:=swig/host
+PKG_BUILD_DEPENDS:=python-setuptools/host swig/host
 CMAKE_INSTALL:=1
 PKG_BUILD_FLAGS:=no-mips16
 PYTHON3_PKG_BUILD:=0
diff --git a/libs/libmraa/patches/003-python-binding-Fix-Python-3-13-compatibility.patch b/libs/libmraa/patches/003-python-binding-Fix-Python-3-13-compatibility.patch
new file mode 100644 (file)
index 0000000..8213501
--- /dev/null
@@ -0,0 +1,51 @@
+From 28fa501b6c5f4df828f4f7ba6a98e3988ec742eb Mon Sep 17 00:00:00 2001
+From: Chun Jiao Zhao <[email protected]>
+Date: Tue, 2 Sep 2025 16:09:53 +0800
+Subject: [PATCH] python-binding: Fix Python 3.13+ compatibility
+
+PyEval_InitThreads and PyEval_CallObject were deprecated since
+Python 3.9 and removed in Python 3.12+ and 3.13+ respectively.
+
+These APIs are unavailable on Debian 13 which ships Python 3.13.
+
+Refer to: https://github.com/eclipse/mraa/issues/1135
+
+Signed-off-by: Chun Jiao Zhao <[email protected]>
+---
+ src/python/mraapy.c     | 6 +++++-
+ src/python/mraapython.i | 6 ++++++
+ 2 files changed, 11 insertions(+), 1 deletion(-)
+
+--- a/src/python/mraapy.c
++++ b/src/python/mraapy.c
+@@ -25,9 +25,13 @@ mraa_python_isr(void (*isr)(void*), void
+     if (arglist == NULL) {
+         syslog(LOG_ERR, "gpio: Py_BuildValue NULL");
+     } else {
++#if PY_VERSION_HEX >= 0x03090000
++        ret = PyObject_CallObject((PyObject*) isr, arglist);
++#else
+         ret = PyEval_CallObject((PyObject*) isr, arglist);
++#endif
+         if (ret == NULL) {
+-            syslog(LOG_ERR, "gpio: PyEval_CallObject failed");
++            syslog(LOG_ERR, "gpio: Python call failed");
+             PyObject *pvalue, *ptype, *ptraceback;
+             PyObject *pvalue_pystr, *ptype_pystr, *ptraceback_pystr;
+             PyObject *pvalue_ustr, *ptype_ustr, *ptraceback_ustr;
+--- a/src/python/mraapython.i
++++ b/src/python/mraapython.i
+@@ -151,7 +151,13 @@ class Spi;
+     // Initialise python threads, this allows use to grab the GIL when we are
+     // required to do so
+     Py_InitializeEx(0);
++#if PY_VERSION_HEX < 0x03090000
++    // PyEval_InitThreads() is deprecated since Python 3.9 and removed in Python 3.12
++    // In Python 3.7+, the GIL is initialized automatically by Py_Initialize()
++    // Only call PyEval_InitThreads() for Python < 3.9
++    // Reference: https://docs.python.org/3/c-api/init.html#c.PyEval_InitThreads
+     PyEval_InitThreads();
++#endif
+     // Add mraa_init() to the module initialisation process and set isr function
+     mraa_result_t res = mraa_init();
+     if (res == MRAA_SUCCESS) {