Richard W.M. Jones
2019-Sep-11 19:42 UTC
[Libguestfs] [PATCH nbdkit] python: Drop support for Python 2.
This patch proposes to drop support for Python 2 in nbdkit. Rather than abruptly drop it everywhere, my proposal is that we point people to nbdkit 1.14 (the current stable version) if they want to continue with Python 2 plugins, while gently reminding them of the upcoming Python 2.7 end of life announcement. Libnbd never supported Python 2. Libguestfs in theory supports Python 2 but I dropped the bindings from Fedora back in March so it's basically never tested now. Libvirt also started to prefer Python 3 over Python 2 back in March. Rich.
Richard W.M. Jones
2019-Sep-11 19:42 UTC
[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
Eric Blake
2019-Sep-11 19:52 UTC
Re: [Libguestfs] [PATCH nbdkit] python: Drop support for Python 2.
On 9/11/19 2:42 PM, Richard W.M. Jones wrote:> 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(-)Progress! Reminds me that I should revisit the patches I originally wrote around Apr 2018 to bump the python plugin to v2 API (but at the time, I had not tested it on python 3, because I was still on a machine using python 2). Those patches may be easier to revive now that my main dev machine is on a newer Fedora version where python3 is now default, and where I don't have to worry about testing the patches for python2 support. ACK. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Daniel P. Berrangé
2019-Sep-12 08:53 UTC
Re: [Libguestfs] [PATCH nbdkit] python: Drop support for Python 2.
On Wed, Sep 11, 2019 at 08:42:29PM +0100, Richard W.M. Jones wrote:> This patch proposes to drop support for Python 2 in nbdkit. > > Rather than abruptly drop it everywhere, my proposal is that we point > people to nbdkit 1.14 (the current stable version) if they want to > continue with Python 2 plugins, while gently reminding them of the > upcoming Python 2.7 end of life announcement. > > Libnbd never supported Python 2. Libguestfs in theory supports > Python 2 but I dropped the bindings from Fedora back in March so it's > basically never tested now. Libvirt also started to prefer Python 3 > over Python 2 back in March.I intend that we will drop python 2 compat in libvirt in the 6.0.0 release ~ Jan 15 2020, as that's the first release after py2 goes EOL by its maintainers. We've already dropped py2 in libvirt-python in Fedora 31. Overall I think its reasonable for nbdkit to drop py2 now, given it has a much narrower userbase and much less legacy platform deployment. Even on RHEL-7 where py2 is the default, you can still get py3 via software collections if needed. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Seemingly Similar Threads
- [PATCH nbdkit] python: Turn python exceptions into nbdkit errors
- [PATCH nbdkit] python: Drop support for Python 2.
- [PATCH 0/7] Various Python cleanups.
- [nbdkit PATCH] python: Let zero's may_trim parameter be optional
- [PATCH nbdkit] python: Turn python exceptions into nbdkit errors properly.