Starting with nbdkit 1.16, Python >= 3.3 will be required.
Python 2 reaches end of life on 2020-01-01:
https://python3statement.org/
https://pythonclock.org/
Debian oldoldstable and RHEL 7 have Python 3.4 and 3.6 respectively,
so it seems pointless to try to support Python < 3.3 which lacked
support for PyUnicode_AsUTF8.
---
README | 13 +++--
configure.ac| 36 ++--
plugins/python/python.c | 31 +--
3 files changed, 22 insertions(+), 58 deletions(-)
diff --git a/README b/README
index 187da49..9752e0b 100644
--- a/README
+++ b/README
@@ -125,8 +125,7 @@ For the Perl, example4 and tar plugins:
For the Python plugin:
- - python interpreter
- (either version 2 or 3 may be used)
+ - python interpreter (version 3 only)
- python development libraries
@@ -201,12 +200,14 @@ Optionally run this command as root to install everything:
Python
--
+Since nbdkit >= 1.16, only Python >= 3.3 is supported.
+
By default nbdkit uses the Python version of the Python interpreter
-called “python” on the current $PATH. To use another version of
-Python you may need to set the PYTHON variable when configuring. For
-example:
+called “python” on the current $PATH. If you have parallel versions
+of Python installed then you can choose a different version by setting
+the PYTHON variable when configuring. For example:
-./configure PYTHON=/usr/bin/python3
+./configure PYTHON=/usr/bin/python3.8
Running the tests
-
diff --git a/configure.ac b/configure.ac
index d326377..e9d2b1f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -470,7 +470,7 @@ AC_SUBST([PERL_ARCHLIB])
AC_SUBST([PERL_CFLAGS])
AC_SUBST([PERL_LDOPTS])
-dnl Check for Python, for embedding in the python plugin.
+dnl Check for Python 3, for embedding in the python plugin.
AC_CHECK_PROG([PYTHON],[python],[python],[no])
AC_ARG_ENABLE([python],
[AS_HELP_STRING([--disable-python], [disable Python embed plugin])],
@@ -488,6 +488,19 @@ AS_IF([test "x$PYTHON" != "xno" && test "x$enable_python"
!= "xno"],[
enable_python=no
])
+AC_MSG_CHECKING([Python major version is 3])
+AS_IF([test "x$PYTHON_VERSION_MAJOR" = "x3"],[
+AC_MSG_RESULT([yes])
+],[
+AC_MSG_RESULT([no])
+AC_MSG_ERROR([Python $PYTHON_VERSION_MAJOR <> 3 is no longer supported.
+
+Python 2 end of life is 2020-01-01 and nbdkit >= 1.16 no longer
+supports it.
+
+If you want to use Python 2, you will need to use nbdkit 1.14.])
+])
+
dnl Check for Python CFLAGS, libraries.
dnl For Python >= 3.8 we have to use python--embed.pc, see:
dnl
https://docs.python.org/3.8/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build
@@ -515,27 +528,6 @@ AS_IF([test "x$PYTHON" != "xno" && test "x$enable_python"
!= "xno"],[
AC_MSG_WARN([python $PYTHON_VERSION not found])
enable_python=no
])])])
-
-dnl Check for various functions needed by the bindings.
-old_LIBS="$LIBS"
-
-PYTHON_BLDLIBRARY=`$PYTHON -c "import distutils.sysconfig; \
-print (distutils.sysconfig.get_config_var('BLDLIBRARY'))"`
-AC_CHECK_LIB([c],[PyString_FromString],
- [AC_DEFINE([HAVE_PYSTRING_FROMSTRING],1,
-[Found PyString_FromString in libpython.])],
- [],[$PYTHON_BLDLIBRARY])
-AC_CHECK_LIB([c],[PyString_AsString],
- [AC_DEFINE([HAVE_PYSTRING_ASSTRING],1,
-[Found PyString_AsString in libpython.])],
- [],[$PYTHON_BLDLIBRARY])
-AC_CHECK_LIB([c],[PyUnicode_AsUTF8],
- [AC_DEFINE([HAVE_PYUNICODE_ASUTF8],1,
-[Found PyUnicode_AsUTF8 in libpython.])],
- [],[$PYTHON_BLDLIBRARY])
-
-LIBS="$old_LIBS"
-
])
AM_CONDITIONAL([HAVE_PYTHON],[test "x$enable_python" != "xno" && test
"x$PYTHON" != "xno"])
AC_SUBST([PYTHON_CFLAGS])
diff --git a/plugins/python/python.c b/plugins/python/python.c
index 20232f4..2e1a53f 100644
--- a/plugins/python/python.c
+++ b/plugins/python/python.c
@@ -117,17 +117,9 @@ static char *
python_to_string (PyObject *str)
{
if (str) {
-#ifdef HAVE_PYUNICODE_ASUTF8
if (PyUnicode_Check (str))
return strdup (PyUnicode_AsUTF8 (str));
-else
-#endif
-#ifdef HAVE_PYSTRING_ASSTRING
-if (PyString_Check (str))
- return strdup (PyString_AsString (str));
-else
-#endif
-if (PyBytes_Check (str))
+else if (PyBytes_Check (str))
return strdup (PyBytes_AS_STRING (str));
}
return NULL;
@@ -159,11 +151,7 @@ print_python_traceback (const char *callback,
*traceback_str;
CLEANUP_FREE char *traceback_cstr = NULL;
-#ifdef HAVE_PYSTRING_FROMSTRING
- module_name = PyString_FromString ("traceback");
-#else
module_name = PyUnicode_FromString ("traceback");
-#endif
traceback_module = PyImport_Import (module_name);
Py_DECREF (module_name);
@@ -222