mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
python: Drop support for Python 2.
Python 2 reached end of life on 2020-01-01: https://python3statement.org/ https://pythonclock.org/ The minimum version required is now Python 3.4 (since that is the version in Debian oldoldstable), but 3.6 is the minimum version that I actually test.
This commit is contained in:
@@ -307,11 +307,10 @@ Optional. For testing the common OCaml modules.
|
||||
|
||||
Optional. Used to build and test the Perl bindings.
|
||||
|
||||
=item Python E<ge> 2.7
|
||||
=item Python E<ge> 3.4
|
||||
|
||||
Optional. Used to build the Python bindings. For building
|
||||
Python 2 or Python 3 bindings, see
|
||||
L</BUILDING PYTHON 2 AND PYTHON 3 BINDINGS> below.
|
||||
Optional. Used to build the Python bindings.
|
||||
S<Python 2> support was removed in S<libguestfs 1.42.1>.
|
||||
|
||||
=item Python C<unittest>
|
||||
|
||||
@@ -528,8 +527,6 @@ If there is a file in the top build directory called F<localenv>, then
|
||||
it will be sourced by C<make>. This file can contain any local
|
||||
environment variables needed, eg. for skipping tests:
|
||||
|
||||
# Use an alternate python binary.
|
||||
export PYTHON=python3
|
||||
# Skip this test, it is broken.
|
||||
export SKIP_TEST_BTRFS_FSCK=1
|
||||
|
||||
@@ -683,8 +680,7 @@ F<appliance/make.sh.in> to understand precisely what this does.
|
||||
This environment variable may be set to point to a python binary
|
||||
(eg. C<python3>). When C<./configure> runs, it inspects this python
|
||||
binary to find the version of Python, the location of Python libraries
|
||||
and so on. See
|
||||
L</BUILDING PYTHON 2 AND PYTHON 3 BINDINGS> below.
|
||||
and so on.
|
||||
|
||||
=item B<SUPERMIN>
|
||||
|
||||
@@ -752,23 +748,6 @@ tarball, eg:
|
||||
and run the libguestfs programs and virt tools in the normal way,
|
||||
eg. using the F<./run> script (see above).
|
||||
|
||||
=head1 BUILDING PYTHON 2 AND PYTHON 3 BINDINGS
|
||||
|
||||
The F<./configure> script detects the currently installed version of
|
||||
Python using whatever program is called C<python> in the current
|
||||
C<$PATH>. Libguestfs will build Python 2 or Python 3 bindings as
|
||||
appropriate.
|
||||
|
||||
You can override this behaviour by specifying an alternate Python
|
||||
binary, eg:
|
||||
|
||||
PYTHON=/usr/bin/python3 ./configure
|
||||
|
||||
To build parallel Python 2 and Python 3 bindings, you will need to
|
||||
build libguestfs twice. The second time, you can disable all the
|
||||
other bindings and tools and just build the Python bindings. See the
|
||||
Fedora spec file (see below) for a complete example of how to do this.
|
||||
|
||||
=head1 BUILDING A PACKAGE FOR FEDORA
|
||||
|
||||
The Fedora spec file is stored under:
|
||||
|
||||
@@ -174,13 +174,8 @@ and generate_python_structs () =
|
||||
pr " goto err;\n";
|
||||
pr " PyDict_SetItemString (dict, \"%s\", value);\n" name;
|
||||
| name, FBuffer ->
|
||||
pr "#if PY_MAJOR_VERSION >= 3\n";
|
||||
pr " value = PyBytes_FromStringAndSize (%s->%s, %s->%s_len);\n"
|
||||
typ name typ name;
|
||||
pr "#else\n";
|
||||
pr " value = PyString_FromStringAndSize (%s->%s, %s->%s_len);\n"
|
||||
typ name typ name;
|
||||
pr "#endif\n";
|
||||
pr " if (value == NULL)\n";
|
||||
pr " goto err;\n";
|
||||
pr " PyDict_SetItemString (dict, \"%s\", value);\n" name;
|
||||
@@ -493,11 +488,7 @@ and generate_python_actions actions () =
|
||||
pr " guestfs_int_free_string_list (r);\n";
|
||||
pr " if (py_r == NULL) goto out;\n";
|
||||
| RBufferOut _ ->
|
||||
pr "#if PY_MAJOR_VERSION >= 3\n";
|
||||
pr " py_r = PyBytes_FromStringAndSize (r, size);\n";
|
||||
pr "#else\n";
|
||||
pr " py_r = PyString_FromStringAndSize (r, size);\n";
|
||||
pr "#endif\n";
|
||||
pr " free (r);\n";
|
||||
pr " if (py_r == NULL) goto out;\n";
|
||||
);
|
||||
@@ -575,7 +566,6 @@ and generate_python_module () =
|
||||
|
||||
(* Init function. *)
|
||||
pr "\
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
static struct PyModuleDef moduledef = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
\"libguestfsmod\", /* m_name */
|
||||
@@ -587,18 +577,13 @@ static struct PyModuleDef moduledef = {
|
||||
NULL, /* m_clear */
|
||||
NULL, /* m_free */
|
||||
};
|
||||
#endif
|
||||
|
||||
static PyObject *
|
||||
moduleinit (void)
|
||||
{
|
||||
PyObject *m;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
m = PyModule_Create (&moduledef);
|
||||
#else
|
||||
m = Py_InitModule ((char *) \"libguestfsmod\", methods);
|
||||
#endif
|
||||
|
||||
if (m != NULL)
|
||||
guestfs_int_py_extend_module (m);
|
||||
@@ -606,7 +591,6 @@ moduleinit (void)
|
||||
return m; /* m might be NULL if module init failed */
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
extern PyMODINIT_FUNC PyInit_libguestfsmod (void);
|
||||
|
||||
PyMODINIT_FUNC
|
||||
@@ -614,15 +598,6 @@ PyInit_libguestfsmod (void)
|
||||
{
|
||||
return moduleinit ();
|
||||
}
|
||||
#else
|
||||
extern void initlibguestfsmod (void);
|
||||
|
||||
void
|
||||
initlibguestfsmod (void)
|
||||
{
|
||||
(void) moduleinit ();
|
||||
}
|
||||
#endif
|
||||
"
|
||||
|
||||
(* Generate Python module. *)
|
||||
|
||||
@@ -19,27 +19,40 @@ dnl Check for Python (optional, for Python bindings).
|
||||
PYTHON_PREFIX=
|
||||
PYTHON_VERSION=
|
||||
PYTHON_INSTALLDIR=
|
||||
PYTHON_REQ_MAJOR=2
|
||||
PYTHON_REQ_MINOR=7
|
||||
|
||||
AC_ARG_ENABLE([python],
|
||||
AS_HELP_STRING([--disable-python], [disable Python language bindings]),
|
||||
[],
|
||||
[enable_python=yes])
|
||||
AS_IF([test "x$enable_python" != "xno"],[
|
||||
AC_CHECK_PROG([PYTHON],[python],[python],[no])
|
||||
AC_CHECK_PROGS([PYTHON],[python3 python],[no])
|
||||
|
||||
if test "x$PYTHON" != "xno"; then
|
||||
AC_MSG_CHECKING([Python version])
|
||||
PYTHON_VERSION_MAJOR=`$PYTHON -c "import sys; print (sys.version_info@<:@0@:>@)"`
|
||||
PYTHON_VERSION_MINOR=`$PYTHON -c "import sys; print (sys.version_info@<:@1@:>@)"`
|
||||
PYTHON_VERSION="$PYTHON_VERSION_MAJOR.$PYTHON_VERSION_MINOR"
|
||||
AS_IF([test "$PYTHON_VERSION_MAJOR" -lt $PYTHON_REQ_MAJOR || ( test "$PYTHON_VERSION_MAJOR" -eq $PYTHON_REQ_MAJOR && test "$PYTHON_VERSION_MINOR" -lt $PYTHON_REQ_MINOR )],[
|
||||
AC_MSG_ERROR([found Python $PYTHON_VERSION, while Python $PYTHON_REQ_MAJOR.$PYTHON_REQ_MINOR is required])
|
||||
AS_IF([test -n "$PYTHON_VERSION"],[
|
||||
AC_MSG_RESULT([$PYTHON_VERSION])
|
||||
],[
|
||||
AC_MSG_NOTICE([Python bindings disabled])
|
||||
enable_python=no
|
||||
])
|
||||
AC_MSG_RESULT([$PYTHON_VERSION])
|
||||
|
||||
# Debian: python-2.7.pc, python-3.2.pc
|
||||
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 libguestfs >= 1.42.1 no longer
|
||||
supports it.
|
||||
|
||||
If you want to use Python 2, you will need to use libguestfs 1.40 or 1.42.0.])
|
||||
])
|
||||
|
||||
# Debian: python-3.2.pc
|
||||
PKG_CHECK_MODULES([PYTHON], [python-"$PYTHON_VERSION"],[
|
||||
have_python_module=1
|
||||
AC_SUBST([PYTHON_CFLAGS])
|
||||
|
||||
@@ -384,30 +384,18 @@ guestfs_int_py_put_table (char * const * const argv)
|
||||
PyObject *
|
||||
guestfs_int_py_fromstring (const char *str)
|
||||
{
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
return PyString_FromString (str);
|
||||
#else
|
||||
return PyUnicode_FromString (str);
|
||||
#endif
|
||||
}
|
||||
|
||||
PyObject *
|
||||
guestfs_int_py_fromstringsize (const char *str, size_t size)
|
||||
{
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
return PyString_FromStringAndSize (str, size);
|
||||
#else
|
||||
return PyUnicode_FromStringAndSize (str, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
char *
|
||||
guestfs_int_py_asstring (PyObject *obj)
|
||||
{
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
return PyString_AsString (obj);
|
||||
#else
|
||||
PyObject *bytes = PyUnicode_AsUTF8String (obj);
|
||||
return PyBytes_AS_STRING (bytes);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user