[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH nbdkit] python: Drop support for Python 2.



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-<VERSION>-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,7 +210,6 @@ check_python_failure (const char *callback)
   return 0;
 }
 
-#if PY_MAJOR_VERSION >= 3
 static struct PyModuleDef moduledef = {
   PyModuleDef_HEAD_INIT,
   "nbdkit",
@@ -234,25 +221,18 @@ static struct PyModuleDef moduledef = {
   NULL,
   NULL
 };
-#endif
 
 static PyMODINIT_FUNC
 create_nbdkit_module (void)
 {
   PyObject *m;
 
-#if PY_MAJOR_VERSION >= 3
   m = PyModule_Create (&moduledef);
-#else
-  m = Py_InitModule ("nbdkit", NbdkitMethods);
-#endif
   if (m == NULL) {
     nbdkit_error ("could not create the nbdkit API module");
     exit (EXIT_FAILURE);
   }
-#if PY_MAJOR_VERSION >= 3
   return m;
-#endif
 }
 
 static void
@@ -276,13 +256,8 @@ py_dump_plugin (void)
   PyObject *fn;
   PyObject *r;
 
-#ifdef PY_VERSION
   printf ("python_version=%s\n", PY_VERSION);
-#endif
-
-#ifdef PYTHON_ABI_VERSION
   printf ("python_pep_384_abi_version=%d\n", PYTHON_ABI_VERSION);
-#endif
 
   if (script && callback_defined ("dump_plugin", &fn)) {
     PyErr_Clear ();
@@ -337,11 +312,7 @@ py_config (const char *key, const char *value)
     /* Note that because closeit flag == 1, fp is now closed. */
 
     /* The script should define a module called __main__. */
-#ifdef HAVE_PYSTRING_FROMSTRING
-    modname = PyString_FromString ("__main__");
-#else
     modname = PyUnicode_FromString ("__main__");
-#endif
     module = PyImport_Import (modname);
     Py_DECREF (modname);
     if (!module) {
-- 
2.23.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]