From: Marc Schink Date: Wed, 21 Aug 2024 07:42:52 +0000 (+0200) Subject: Drop Python 2 support X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3ce3e67a3170fc76193ee9e5232a7eec046e1197;p=libsigrok.git Drop Python 2 support 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 --- diff --git a/README b/README index c870a0bb..9f56b968 100644 --- 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) diff --git a/bindings/cxx/enums.py b/bindings/cxx/enums.py index 388faf22..cd91e980 100644 --- a/bindings/cxx/enums.py +++ b/bindings/cxx/enums.py @@ -17,7 +17,6 @@ ## along with this program. If not, see . ## -from __future__ import print_function from xml.etree import ElementTree from collections import OrderedDict import sys, os, re diff --git a/bindings/python/sigrok/core/classes.i b/bindings/python/sigrok/core/classes.i index 2e273c47..b0b7fcfa 100644 --- a/bindings/python/sigrok/core/classes.i +++ b/bindings/python/sigrok/core/classes.i @@ -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 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::create(PyInt_AsLong(input)); if (type == SR_T_UINT64 && PyLong_Check(input)) return Glib::Variant::create(PyLong_AsLong(input)); - else if (type == SR_T_STRING && string_check(input)) - return Glib::Variant::create(string_from_python(input)); + else if (type == SR_T_STRING && PyUnicode_Check(input)) + return Glib::Variant::create(PyUnicode_AsUTF8(input)); else if (type == SR_T_BOOL && PyBool_Check(input)) return Glib::Variant::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::create(PyInt_AsLong(input)); if (type == G_VARIANT_TYPE_UINT64 && PyLong_Check(input)) return Glib::Variant::create(PyLong_AsLong(input)); - else if (type == G_VARIANT_TYPE_STRING && string_check(input)) - return Glib::Variant::create(string_from_python(input)); + else if (type == G_VARIANT_TYPE_STRING && PyUnicode_Check(input)) + return Glib::Variant::create(PyUnicode_AsUTF8(input)); else if (type == G_VARIANT_TYPE_BOOLEAN && PyBool_Check(input)) return Glib::Variant::create(input == Py_True); else if (type == G_VARIANT_TYPE_DOUBLE && PyFloat_Check(input)) @@ -402,9 +388,9 @@ std::map 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 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; } diff --git a/bindings/swig/doc.py b/bindings/swig/doc.py index 182f5477..c2e66958 100644 --- a/bindings/swig/doc.py +++ b/bindings/swig/doc.py @@ -17,7 +17,6 @@ ## along with this program. If not, see . ## -from __future__ import print_function from xml.etree import ElementTree import sys, os diff --git a/configure.ac b/configure.ac index 1da1bad8..024dd4da 100644 --- a/configure.ac +++ b/configure.ac @@ -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],