[libvirt] [libvirt-glib][PATCH 0/2] Support python3

/usr/bin/python defaults to python3 on my system. While trying to build libvirt-glib I've noticed some errors in configure (first patch), and some missing implementation (second patch). Michal Privoznik (2): configure: Detect python in compatible fashion python: Introduce support for python3 configure.ac | 6 +++--- python/libvirt-glib.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) -- 2.8.4

In the configure script we try to detect what version of python is there currently installed on the system. We use `python -c "some cmd"` to find out. However, the syntax we use for "some cmd" is plainly just for 2.x and throws an error for 3.x. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 8edde74..91929e8 100644 --- a/configure.ac +++ b/configure.ac @@ -200,7 +200,7 @@ if test "$with_python" != "no" ; then if test -x "$PYTHON" then echo Found python in environment PYTHON=$PYTHON - with_python=`$PYTHON -c "import sys; print sys.exec_prefix"` + with_python=`$PYTHON -c "import sys; print(sys.exec_prefix)"` else AC_PATH_PROG([PYTHON], [python python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5]) fi @@ -208,7 +208,7 @@ if test "$with_python" != "no" ; then fi if test "$PYTHON" != "" then - PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[[0:3]]"` + PYTHON_VERSION=`$PYTHON -c "import sys; print(sys.version[[0:3]])"` echo Found Python version $PYTHON_VERSION fi if test "$PYTHON_VERSION" != "" @@ -234,7 +234,7 @@ if test "$with_python" != "no" ; then fi if test ! -d "$PYTHON_SITE_PACKAGES" then - PYTHON_SITE_PACKAGES=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib()"` + PYTHON_SITE_PACKAGES=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_lib())"` fi fi fi -- 2.8.4

On Mon, Aug 01, 2016 at 11:47:42AM +0200, Michal Privoznik wrote:
In the configure script we try to detect what version of python is there currently installed on the system. We use `python -c "some cmd"` to find out. However, the syntax we use for "some cmd" is plainly just for 2.x and throws an error for 3.x.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
IMHO we should just delete the python binding instead. It only ever supported 1 symbol - the gvir_event_register() method. GObject introspection support in PyGObject has existed for more than long enough at this point, that a manual binding is a waste of time. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Just like libvirt itself is able to work with both major version of python, libvirt-glib should do the same. Even the code I'm introducing here is copied from there (and changed slightly to reflect project name). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- python/libvirt-glib.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/python/libvirt-glib.c b/python/libvirt-glib.c index 1daca36..8b3920d 100644 --- a/python/libvirt-glib.c +++ b/python/libvirt-glib.c @@ -17,11 +17,19 @@ #include <glib.h> #include "libvirt-glib/libvirt-glib.h" +#if PY_MAJOR_VERSION > 2 +# ifndef __CYGWIN__ +extern PyObject *PyInit_libvirtglibmod(void); +# else +extern PyObject *PyInit_cygvirtglibmod(void); +# endif +#else #ifndef __CYGWIN__ extern void initlibvirtglibmod(void); #else extern void initcygvirtglibmod(void); #endif +#endif #define VIR_PY_NONE (Py_INCREF (Py_None), Py_None) @@ -38,6 +46,41 @@ static PyMethodDef libvirtGLibMethods[] = { {NULL, NULL, 0, NULL} }; +#if PY_MAJOR_VERSION > 2 +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, +# ifndef __CYGWIN__ + "libvirtglibmod", +# else + "cygvirtglibmod", +# endif + NULL, + -1, + libvirtGLibMethods, + NULL, + NULL, + NULL, + NULL +}; + +PyObject * +# ifndef __CYGWIN__ +PyInit_libvirtglibmod +# else +PyInit_cygvirtglibmod +# endif +(void) +{ + PyObject *module; + + if (gvir_init_check(NULL, NULL, NULL) < 0) + return NULL; + + module = PyModule_Create(&moduledef); + + return module; +} +#else /* ! PY_MAJOR_VERSION > 2 */ void #ifndef __CYGWIN__ initlibvirtglibmod @@ -57,3 +100,4 @@ initcygvirtglibmod , libvirtGLibMethods); } +#endif /* ! PY_MAJOR_VERSION > 2 */ -- 2.8.4

On Mon, Aug 01, 2016 at 11:47:43AM +0200, Michal Privoznik wrote:
Just like libvirt itself is able to work with both major version of python, libvirt-glib should do the same. Even the code I'm introducing here is copied from there (and changed slightly to reflect project name).
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- python/libvirt-glib.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
diff --git a/python/libvirt-glib.c b/python/libvirt-glib.c index 1daca36..8b3920d 100644 --- a/python/libvirt-glib.c +++ b/python/libvirt-glib.c @@ -17,11 +17,19 @@ #include <glib.h> #include "libvirt-glib/libvirt-glib.h"
+#if PY_MAJOR_VERSION > 2 +# ifndef __CYGWIN__ +extern PyObject *PyInit_libvirtglibmod(void); +# else +extern PyObject *PyInit_cygvirtglibmod(void); +# endif +#else #ifndef __CYGWIN__ extern void initlibvirtglibmod(void); #else extern void initcygvirtglibmod(void); #endif
I'd expect this to be re-indented, but make syntax-check doesn't say anything. Other than that, I have no idea about glib, but the patches work for me...
participants (3)
-
Daniel P. Berrange
-
Martin Kletzander
-
Michal Privoznik