]> sigrok.org Git - libsigrok.git/commitdiff
Drop Python 2 support
authorMarc Schink <redacted>
Wed, 21 Aug 2024 07:42:52 +0000 (09:42 +0200)
committerSoeren Apel <redacted>
Thu, 20 Nov 2025 18:00:01 +0000 (19:00 +0100)
Python 2 reached its official end-of-life in 2020 and is no longer
supported. Use the oldest but still maintained Python 3 version as
minimum requirement.

Signed-off-by: Marc Schink <redacted>
README
bindings/cxx/enums.py
bindings/python/sigrok/core/classes.i
bindings/swig/doc.py
configure.ac

diff --git a/README b/README
index c870a0bba68d77fd30768985c43a0e40fe2f7396..9f56b968d80d5c030d839a5c35b67c00d2002835 100644 (file)
--- a/README
+++ b/README
@@ -63,17 +63,17 @@ Requirements for the C++ bindings:
  - autoconf-archive (only needed when building from git)
  - doxygen (required for building the bindings, not only for C++ API docs!)
  - graphviz (optional, only needed for the C++ API docs)
- - Python (2 or 3) executable (development files are not needed)
+ - Python 3 executable (development files are not needed)
  - glibmm-2.4 (>= 2.32.0) or glibmm-2.68 (>= 2.68.0)
 
 Requirements for the Python bindings:
 
  - libsigrokcxx >= 0.4.0 (the libsigrok C++ bindings, see above)
- - Python >= 2.7 or Python >= 3 (including development files!)
- - Python setuptools (for Python 2 or 3)
- - pygobject >= 3.0.0 (for Python 2 or 3), a.k.a python-gi
- - numpy (for Python 2 or 3)
  - SWIG >= 2.0.0
+ - Python >= 3 (including development files!)
+ - Python setuptools
+ - pygobject >= 3.0.0, a.k.a python-gi
+ - numpy
  - doxygen (optional, only needed for the Python API docs)
  - graphviz (optional, only needed for the Python API docs)
  - doxypy (optional, only needed for the Python API docs)
index 388faf2255de9b123634fee507feec4301db5c47..cd91e980d7d9503c8f89de844fc9a294723719e2 100644 (file)
@@ -17,7 +17,6 @@
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ##
 
-from __future__ import print_function
 from xml.etree import ElementTree
 from collections import OrderedDict
 import sys, os, re
index 2e273c4752fb73c1628c8b4a151cdf2fe5a67dfa..b0b7fcfa94dc06899a8357331a7047de734a6d0f 100644 (file)
@@ -61,16 +61,6 @@ typedef gint pyg_flags_type;
 typedef guint pyg_flags_type;
 #endif
 
-#if PY_VERSION_HEX >= 0x03000000
-#define string_check PyUnicode_Check
-#define string_from_python PyUnicode_AsUTF8
-#define string_to_python PyUnicode_FromString
-#else
-#define string_check PyString_Check
-#define string_from_python PyString_AsString
-#define string_to_python PyString_FromString
-#endif
-
 %}
 
 %init %{
@@ -84,11 +74,7 @@ typedef guint pyg_flags_type;
      */
     if (!GLib) {
         fprintf(stderr, "Import of gi.repository.GLib failed.\n");
-#if PY_VERSION_HEX >= 0x03000000
         return nullptr;
-#else
-        return;
-#endif
     }
     import_array();
 %}
@@ -130,7 +116,7 @@ typedef guint pyg_flags_type;
         auto log_obj = SWIG_NewPointerObj(
                 SWIG_as_voidptr(loglevel), SWIGTYPE_p_sigrok__LogLevel, 0);
 
-        auto string_obj = string_to_python(message.c_str());
+        auto string_obj = PyUnicode_FromString(message.c_str());
 
         auto arglist = Py_BuildValue("(OO)", log_obj, string_obj);
 
@@ -311,12 +297,12 @@ std::map<std::string, std::string> dict_to_map_string(PyObject *dict)
     Py_ssize_t pos = 0;
 
     while (PyDict_Next(dict, &pos, &py_key, &py_value)) {
-        if (!string_check(py_key))
+        if (!PyUnicode_Check(py_key))
             throw sigrok::Error(SR_ERR_ARG);
-        if (!string_check(py_value))
+        if (!PyUnicode_Check(py_value))
             throw sigrok::Error(SR_ERR_ARG);
-        auto key = string_from_python(py_key);
-        auto value = string_from_python(py_value);
+        auto key = PyUnicode_AsUTF8(py_key);
+        auto value = PyUnicode_AsUTF8(py_value);
         output[key] = value;
     }
 
@@ -332,8 +318,8 @@ Glib::VariantBase python_to_variant_by_key(PyObject *input, const sigrok::Config
         return Glib::Variant<guint64>::create(PyInt_AsLong(input));
     if (type == SR_T_UINT64 && PyLong_Check(input))
         return Glib::Variant<guint64>::create(PyLong_AsLong(input));
-    else if (type == SR_T_STRING && string_check(input))
-        return Glib::Variant<Glib::ustring>::create(string_from_python(input));
+    else if (type == SR_T_STRING && PyUnicode_Check(input))
+        return Glib::Variant<Glib::ustring>::create(PyUnicode_AsUTF8(input));
     else if (type == SR_T_BOOL && PyBool_Check(input))
         return Glib::Variant<bool>::create(input == Py_True);
     else if (type == SR_T_FLOAT && PyFloat_Check(input))
@@ -375,8 +361,8 @@ Glib::VariantBase python_to_variant_by_option(PyObject *input,
         return Glib::Variant<guint64>::create(PyInt_AsLong(input));
     if (type == G_VARIANT_TYPE_UINT64 && PyLong_Check(input))
         return Glib::Variant<guint64>::create(PyLong_AsLong(input));
-    else if (type == G_VARIANT_TYPE_STRING && string_check(input))
-        return Glib::Variant<Glib::ustring>::create(string_from_python(input));
+    else if (type == G_VARIANT_TYPE_STRING && PyUnicode_Check(input))
+        return Glib::Variant<Glib::ustring>::create(PyUnicode_AsUTF8(input));
     else if (type == G_VARIANT_TYPE_BOOLEAN && PyBool_Check(input))
         return Glib::Variant<bool>::create(input == Py_True);
     else if (type == G_VARIANT_TYPE_DOUBLE && PyFloat_Check(input))
@@ -402,9 +388,9 @@ std::map<std::string, Glib::VariantBase> dict_to_map_options(PyObject *dict,
     Py_ssize_t pos = 0;
 
     while (PyDict_Next(dict, &pos, &py_key, &py_value)) {
-        if (!string_check(py_key))
+        if (!PyUnicode_Check(py_key))
             throw sigrok::Error(SR_ERR_ARG);
-        auto key = string_from_python(py_key);
+        auto key = PyUnicode_AsUTF8(py_key);
         auto value = python_to_variant_by_option(py_value, options[key]);
         output[key] = value;
     }
@@ -490,9 +476,9 @@ std::map<std::string, Glib::VariantBase> dict_to_map_options(PyObject *dict,
 
         while (PyDict_Next(dict, &pos, &py_key, &py_value))
         {
-            if (!string_check(py_key))
+            if (!PyUnicode_Check(py_key))
                 throw sigrok::Error(SR_ERR_ARG);
-            auto key = sigrok::ConfigKey::get_by_identifier(string_from_python(py_key));
+            auto key = sigrok::ConfigKey::get_by_identifier(PyUnicode_AsUTF8(py_key));
             auto value = python_to_variant_by_key(py_value, key);
             options[key] = value;
         }
index 182f547719eacf5f9538f2b57848b4a2d3e43563..c2e669587fb9b3f1c10bed7b18bf547bd41d93d1 100644 (file)
@@ -17,7 +17,6 @@
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ##
 
-from __future__ import print_function
 from xml.etree import ElementTree
 import sys, os
 
index 1da1bad8017af3ce07d07d0e460ac325dedbcf77..024dd4da2139e3a9b47f3962df7ae0951e4598e4 100644 (file)
@@ -476,7 +476,7 @@ AS_IF([test "x$HAVE_DOXYGEN" != xyes],
 SR_SEARCH_LIBS([SR_EXTRA_CXX_LIBS], [__cxa_throw], [gnustl_shared])
 
 # Python is needed for the C++ bindings.
-AM_PATH_PYTHON([2.7],
+AM_PATH_PYTHON([3.8],
        [HAVE_PYTHON=yes],
        [HAVE_PYTHON=no
        SR_APPEND([sr_cxx_missing], [', '], [Python])])
@@ -519,7 +519,7 @@ sr_pymajor=${PYTHON_VERSION%%.*}
 sr_pyminor=${PYTHON_VERSION#*.}
 
 # The Python bindings need Python development files. Check for either
-# Python 3 or Python 2 headers depending on the interpreter version.
+# Python 3 headers depending on the interpreter version.
 SR_PKG_CHECK([python_dev], [SR_PKGLIBS_PYTHON],
        [python = $PYTHON_VERSION],
        [python$sr_pymajor = $PYTHON_VERSION],