From nobody Thu May 2 15:32:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1575456141; cv=none; d=zohomail.com; s=zohoarc; b=SkO4bvYboxLCe1yKLRYWKiscR/1g1gsR4eDuGeyNjAaMjnIUbo2R3CRrTDg7O8qI1ElCbMt2juBtqfU06uJbfNQMW/9SDEE0ipvRqYF2njmbfvPNzTG/2HY+AYikAFZjgX/yXyYfUJ6Nsk27g73y5SdWb474PGH6alLRIvtJYpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575456141; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=KwurNCqNvo4vVCB7aux6t1iUCtWtKBpt8xCZuhVbxtE=; b=PcnqxIauEKb+luMD4BjFrZiKlYz8opkpA1061Pr2b5LvihMyKK9PAKnqoH0hB4VyXEfkkLpXSOGSA7Y/oTuM4JvjfCWBYDI7UKj2vijGijH2S4A8emwZtXaZbf2aWiB51dT8g6OJGutF1PC85o8EIi09qws5rQ2OolOLJfzLiNE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1575456141469477.22219761576537; Wed, 4 Dec 2019 02:42:21 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-280-JjdG4jZiMQ-M6uQFQddLEQ-1; Wed, 04 Dec 2019 05:42:15 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 190D9802C99; Wed, 4 Dec 2019 10:42:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7E4C60BE0; Wed, 4 Dec 2019 10:42:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F02CD1809567; Wed, 4 Dec 2019 10:42:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB4Ag1ml026434 for ; Wed, 4 Dec 2019 05:42:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id 973885DA75; Wed, 4 Dec 2019 10:42:01 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-94.gsslab.fab.redhat.com [10.33.9.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id B562C5DA32; Wed, 4 Dec 2019 10:41:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575456140; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=KwurNCqNvo4vVCB7aux6t1iUCtWtKBpt8xCZuhVbxtE=; b=dVhJo/+GpROU23Jw9KKLRi9Ex/v8/sJuftFVVKmEd+WtZHGI4gvX91Ekgk35NmW5qJiGaH eO3NtAh0xp6cinYjLJKB3+oM8KbBnR1TXOlMJhBSM9xcD+Gn40HHf/uU9lPUcMekRl0l7p 41EYJy7NuvGI80fZfozIoMQd4snjjAI= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 4 Dec 2019 10:41:54 +0000 Message-Id: <20191204104154.6463-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [python PATCH] Drop support for python 2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: JjdG4jZiMQ-M6uQFQddLEQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- examples/consolecallback.py | 2 +- examples/dhcpleases.py | 2 +- examples/dominfo.py | 2 +- examples/domipaddrs.py | 2 +- examples/domrestore.py | 2 +- examples/domsave.py | 2 +- examples/domstart.py | 2 +- examples/esxlist.py | 2 +- examples/event-test.py | 2 +- examples/guest-vcpus/guest-vcpu-daemon.py | 2 +- examples/guest-vcpus/guest-vcpu.py | 2 +- examples/nodestats.py | 2 +- examples/sparsestream.py | 2 +- examples/topology.py | 2 +- generator.py | 2 +- libvirt-lxc-override.c | 51 ++------- libvirt-override.c | 51 ++------- libvirt-python.spec.in | 96 +--------------- libvirt-qemu-override.c | 51 ++------- libvirt-utils.c | 17 +-- libvirt-utils.h | 6 +- sanitytest.py | 2 +- setup.py | 9 +- typewrappers.c | 133 +++------------------- typewrappers.h | 5 - 25 files changed, 71 insertions(+), 380 deletions(-) diff --git a/examples/consolecallback.py b/examples/consolecallback.py index c539a92..1347384 100644 --- a/examples/consolecallback.py +++ b/examples/consolecallback.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # consolecallback - provide a persistent console that survives guest reboo= ts =20 import sys, os, logging, libvirt, tty, termios, atexit diff --git a/examples/dhcpleases.py b/examples/dhcpleases.py index da51f52..f394541 100755 --- a/examples/dhcpleases.py +++ b/examples/dhcpleases.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # netdhcpleases - print leases info for given virtual network =20 import libvirt diff --git a/examples/dominfo.py b/examples/dominfo.py index d3049cd..0a39f4c 100755 --- a/examples/dominfo.py +++ b/examples/dominfo.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # dominfo - print some information about a domain =20 import libvirt diff --git a/examples/domipaddrs.py b/examples/domipaddrs.py index d6d5cac..bda308c 100755 --- a/examples/domipaddrs.py +++ b/examples/domipaddrs.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # domipaddrs - print domain interfaces along with their MAC and IP address= es =20 import libvirt diff --git a/examples/domrestore.py b/examples/domrestore.py index 06fdfbc..96f4955 100755 --- a/examples/domrestore.py +++ b/examples/domrestore.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # domstart - make sure a given domU is running, if not start it =20 import libvirt diff --git a/examples/domsave.py b/examples/domsave.py index 727217c..4940cce 100755 --- a/examples/domsave.py +++ b/examples/domsave.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # domstart - make sure a given domU is running, if not start it =20 import libvirt diff --git a/examples/domstart.py b/examples/domstart.py index ce1b60c..7ff6cb9 100755 --- a/examples/domstart.py +++ b/examples/domstart.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # domstart - make sure a given domU is running, if not start it =20 import libvirt diff --git a/examples/esxlist.py b/examples/esxlist.py index 0d47b00..d86e064 100755 --- a/examples/esxlist.py +++ b/examples/esxlist.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # esxlist - list active domains of an ESX host and print some info. # also demonstrates how to use the libvirt.openAuth() method =20 diff --git a/examples/event-test.py b/examples/event-test.py index 4458e22..fddef64 100755 --- a/examples/event-test.py +++ b/examples/event-test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # # diff --git a/examples/guest-vcpus/guest-vcpu-daemon.py b/examples/guest-vcp= us/guest-vcpu-daemon.py index c7c08a8..30fcb9c 100755 --- a/examples/guest-vcpus/guest-vcpu-daemon.py +++ b/examples/guest-vcpus/guest-vcpu-daemon.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 =20 import libvirt import threading diff --git a/examples/guest-vcpus/guest-vcpu.py b/examples/guest-vcpus/gues= t-vcpu.py index 8faba87..479ec40 100755 --- a/examples/guest-vcpus/guest-vcpu.py +++ b/examples/guest-vcpus/guest-vcpu.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 =20 import libvirt import sys diff --git a/examples/nodestats.py b/examples/nodestats.py index c01dead..ae2a442 100755 --- a/examples/nodestats.py +++ b/examples/nodestats.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Print some host NUMA node statistics # # Authors: diff --git a/examples/sparsestream.py b/examples/sparsestream.py index e960c40..d7c09b7 100755 --- a/examples/sparsestream.py +++ b/examples/sparsestream.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Example of sparse streams usage # # Authors: diff --git a/examples/topology.py b/examples/topology.py index 191669c..197c87a 100755 --- a/examples/topology.py +++ b/examples/topology.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Parse topology information from the capabilities XML and use # them to calculate host topology # diff --git a/generator.py b/generator.py index 3352521..cba9d47 100755 --- a/generator.py +++ b/generator.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # generate python wrappers from the XML API description # diff --git a/libvirt-lxc-override.c b/libvirt-lxc-override.c index d7af154..138ba5b 100644 --- a/libvirt-lxc-override.c +++ b/libvirt-lxc-override.c @@ -4,13 +4,13 @@ * entry points where an automatically generated stub is * unpractical * - * Copyright (C) 2012-2013 Red Hat, Inc. + * Copyright (C) 2012-2019 Red Hat, Inc. * * Daniel Veillard */ =20 /* Horrible kludge to work around even more horrible name-space pollution - via Python.h. That file includes /usr/include/python2.5/pyconfig*.h, + via Python.h. That file includes /usr/include/python3.x/pyconfig*.h, which has over 180 autoconf-style HAVE_* definitions. Shame on them. = */ #undef HAVE_PTHREAD_H =20 @@ -21,18 +21,10 @@ #include "libvirt-utils.h" #include "build/libvirt-lxc.h" =20 -#if PY_MAJOR_VERSION > 2 -# ifndef __CYGWIN__ +#ifndef __CYGWIN__ extern PyObject *PyInit_libvirtmod_lxc(void); -# else -extern PyObject *PyInit_cygvirtmod_lxc(void); -# endif #else -# ifndef __CYGWIN__ -extern void initlibvirtmod_lxc(void); -# else -extern void initcygvirtmod_lxc(void); -# endif +extern PyObject *PyInit_cygvirtmod_lxc(void); #endif =20 #if 0 @@ -107,14 +99,13 @@ static PyMethodDef libvirtLxcMethods[] =3D { {NULL, NULL, 0, NULL} }; =20 -#if PY_MAJOR_VERSION > 2 static struct PyModuleDef moduledef =3D { PyModuleDef_HEAD_INIT, -# ifndef __CYGWIN__ +#ifndef __CYGWIN__ "libvirtmod_lxc", -# else +#else "cygvirtmod_lxc", -# endif +#endif NULL, -1, libvirtLxcMethods, @@ -125,11 +116,11 @@ static struct PyModuleDef moduledef =3D { }; =20 PyObject * -# ifndef __CYGWIN__ +#ifndef __CYGWIN__ PyInit_libvirtmod_lxc -# else +#else PyInit_cygvirtmod_lxc -# endif +#endif (void) { PyObject *module; @@ -141,25 +132,3 @@ PyInit_cygvirtmod_lxc =20 return module; } -#else /* ! PY_MAJOR_VERSION > 2 */ -void -# ifndef __CYGWIN__ -initlibvirtmod_lxc -# else -initcygvirtmod_lxc -# endif -(void) -{ - if (virInitialize() < 0) - return; - - /* initialize the python extension module */ - Py_InitModule((char *) -# ifndef __CYGWIN__ - "libvirtmod_lxc", -# else - "cygvirtmod_lxc", -# endif - libvirtLxcMethods); -} -#endif /* ! PY_MAJOR_VERSION > 2 */ diff --git a/libvirt-override.c b/libvirt-override.c index 2e24d27..4e4c00a 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -4,13 +4,13 @@ * entry points where an automatically generated stub is * unpractical * - * Copyright (C) 2005, 2007-2015 Red Hat, Inc. + * Copyright (C) 2005-2019 Red Hat, Inc. * * Daniel Veillard */ =20 /* Horrible kludge to work around even more horrible name-space pollution - via Python.h. That file includes /usr/include/python2.5/pyconfig*.h, + via Python.h. That file includes /usr/include/python3.x/pyconfig*.h, which has over 180 autoconf-style HAVE_* definitions. Shame on them. = */ #undef HAVE_PTHREAD_H =20 @@ -25,18 +25,10 @@ #include "build/libvirt.h" #include "libvirt-utils.h" =20 -#if PY_MAJOR_VERSION > 2 -# ifndef __CYGWIN__ +#ifndef __CYGWIN__ extern PyObject *PyInit_libvirtmod(void); -# else -extern PyObject *PyInit_cygvirtmod(void); -# endif #else -# ifndef __CYGWIN__ -extern void initlibvirtmod(void); -# else -extern void initcygvirtmod(void); -# endif +extern PyObject *PyInit_cygvirtmod(void); #endif =20 #if 0 @@ -10553,14 +10545,13 @@ static PyMethodDef libvirtMethods[] =3D { {NULL, NULL, 0, NULL} }; =20 -#if PY_MAJOR_VERSION > 2 static struct PyModuleDef moduledef =3D { PyModuleDef_HEAD_INIT, -# ifndef __CYGWIN__ +#ifndef __CYGWIN__ "libvirtmod", -# else +#else "cygvirtmod", -# endif +#endif NULL, -1, libvirtMethods, @@ -10571,11 +10562,11 @@ static struct PyModuleDef moduledef =3D { }; =20 PyObject * -# ifndef __CYGWIN__ +#ifndef __CYGWIN__ PyInit_libvirtmod -# else +#else PyInit_cygvirtmod -# endif +#endif (void) { PyObject *module; @@ -10587,25 +10578,3 @@ PyInit_cygvirtmod =20 return module; } -#else /* ! PY_MAJOR_VERSION > 2 */ -void -# ifndef __CYGWIN__ -initlibvirtmod -# else -initcygvirtmod -# endif -(void) -{ - if (virInitialize() < 0) - return; - - /* initialize the python extension module */ - Py_InitModule((char *) -# ifndef __CYGWIN__ - "libvirtmod", -# else - "cygvirtmod", -# endif - libvirtMethods); -} -#endif /* ! PY_MAJOR_VERSION > 2 */ diff --git a/libvirt-python.spec.in b/libvirt-python.spec.in index 8506840..1e92f3c 100644 --- a/libvirt-python.spec.in +++ b/libvirt-python.spec.in @@ -12,26 +12,7 @@ %define supported_platform 0 %endif =20 -%define _with_python2 1 -%if 0%{?fedora} > 30 || 0%{?rhel} > 7 -%define _with_python2 0 -%endif - -%define _with_python3 0 -%if 0%{?fedora} || 0%{?rhel} > 7 -%define _with_python3 1 -%endif - -# Whether py2 packages are assumed to have python2- name prefix -%define py2_versioned_deps 0 -%if 0%{?fedora} || 0%{?rhel} > 7 -%define py2_versioned_deps 1 -%endif - -%{!?with_python2: %define with_python2 %{_with_python2}} -%{!?with_python3: %define with_python3 %{_with_python3}} - -Summary: The libvirt virtualization API python2 binding +Summary: The libvirt virtualization API python3 binding Name: libvirt-python Version: @PY_VERSION@ Release: 1%{?dist} @@ -39,31 +20,13 @@ Source0: http://libvirt.org/sources/python/%{name}-%{ve= rsion}.tar.gz Url: http://libvirt.org License: LGPLv2+ BuildRequires: libvirt-devel =3D=3D %{version} -%if %{with_python2} -%if %{py2_versioned_deps} -BuildRequires: python2-devel -BuildRequires: python2-nose -BuildRequires: python2-lxml -%else -BuildRequires: python-devel -BuildRequires: python-nose -BuildRequires: python-lxml -%endif -%endif -%if %{with_python3} BuildRequires: python3-devel BuildRequires: python3-nose BuildRequires: python3-lxml -%endif BuildRequires: gcc =20 # Don't want provides for python shared objects -%if %{with_python2} -%{?filter_provides_in: %filter_provides_in %{python2_sitearch}/.*\.so} -%endif -%if %{with_python3} %{?filter_provides_in: %filter_provides_in %{python3_sitearch}/.*\.so} -%endif %{?filter_setup} =20 %description @@ -72,23 +35,6 @@ written in the Python programming language to use the in= terface supplied by the libvirt library to use the virtualization capabilities of recent versions of Linux (and other OSes). =20 -%if %{with_python2} -%package -n python2-libvirt -Summary: The libvirt virtualization API python2 binding -Url: http://libvirt.org -License: LGPLv2+ -%{?python_provide:%python_provide python2-libvirt} -Provides: libvirt-python =3D %{version}-%{release} -Obsoletes: libvirt-python <=3D 3.6.0-1%{?dist} - -%description -n python2-libvirt -The python2-libvirt package contains a module that permits applications -written in the Python programming language to use the interface -supplied by the libvirt library to use the virtualization capabilities -of recent versions of Linux (and other OSes). -%endif - -%if %{with_python3} %package -n python3-libvirt Summary: The libvirt virtualization API python3 binding Url: http://libvirt.org @@ -99,16 +45,15 @@ Obsoletes: libvirt-python3 <=3D 3.6.0-1%{?dist} =20 %description -n python3-libvirt The python3-libvirt package contains a module that permits applications -written in the Python programming language to use the interface +written in the Python 3.x programming language to use the interface supplied by the libvirt library to use the virtualization capabilities of recent versions of Linux (and other OSes). -%endif =20 %prep %setup -q =20 # Unset execute bit for example scripts; it can introduce spurious -# RPM dependencies, like /usr/bin/python which can pull in python2 +# RPM dependencies, like /usr/bin/python3 # for the -python3 package find examples -type f -exec chmod 0644 \{\} \; =20 @@ -118,56 +63,22 @@ echo "This RPM requires either Fedora >=3D %{min_fedor= a} or RHEL >=3D %{min_rhel}" exit 1 %endif =20 -%if %{with_python2} -%if 0%{?fedora} || 0%{?rhel} >=3D 8 -%py2_build -%else -CFLAGS=3D"$RPM_OPT_FLAGS" %{__python2} setup.py build -%endif -%endif -%if %{with_python3} %if 0%{?fedora} || 0%{?rhel} >=3D 8 %py3_build %else CFLAGS=3D"$RPM_OPT_FLAGS" %{__python3} setup.py build %endif -%endif =20 %install -%if %{with_python2} -%if 0%{?fedora} || 0%{?rhel} >=3D 8 -%py2_install -%else -%{__python2} setup.py install --skip-build --root=3D%{buildroot} -%endif -%endif -%if %{with_python3} %if 0%{?fedora} || 0%{?rhel} >=3D 8 %py3_install %else %{__python3} setup.py install --skip-build --root=3D%{buildroot} %endif -%endif =20 %check -%if %{with_python2} -%{__python2} setup.py test -%endif -%if %{with_python3} %{__python3} setup.py test -%endif =20 -%if %{with_python2} -%files -n python2-libvirt -%doc ChangeLog AUTHORS NEWS README COPYING COPYING.LESSER examples/ -%{python2_sitearch}/libvirt.py* -%{python2_sitearch}/libvirt_qemu.py* -%{python2_sitearch}/libvirt_lxc.py* -%{python2_sitearch}/libvirtmod* -%{python2_sitearch}/*egg-info -%endif - -%if %{with_python3} %files -n python3-libvirt %doc ChangeLog AUTHORS NEWS README COPYING COPYING.LESSER examples/ %{python3_sitearch}/libvirt.py* @@ -180,6 +91,5 @@ CFLAGS=3D"$RPM_OPT_FLAGS" %{__python3} setup.py build %{python3_sitearch}/__pycache__/libvirtaio.cpython-*.py* %{python3_sitearch}/libvirtmod* %{python3_sitearch}/*egg-info -%endif =20 %changelog diff --git a/libvirt-qemu-override.c b/libvirt-qemu-override.c index f166f6e..6ae95b4 100644 --- a/libvirt-qemu-override.c +++ b/libvirt-qemu-override.c @@ -4,13 +4,13 @@ * entry points where an automatically generated stub is * unpractical * - * Copyright (C) 2011-2014 Red Hat, Inc. + * Copyright (C) 2011-2019 Red Hat, Inc. * * Daniel Veillard */ =20 /* Horrible kludge to work around even more horrible name-space pollution - via Python.h. That file includes /usr/include/python2.5/pyconfig*.h, + via Python.h. That file includes /usr/include/python3.x/pyconfig*.h, which has over 180 autoconf-style HAVE_* definitions. Shame on them. = */ #undef HAVE_PTHREAD_H =20 @@ -21,18 +21,10 @@ #include "libvirt-utils.h" #include "build/libvirt-qemu.h" =20 -#if PY_MAJOR_VERSION > 2 -# ifndef __CYGWIN__ +#ifndef __CYGWIN__ extern PyObject *PyInit_libvirtmod_qemu(void); -# else -extern PyObject *PyInit_cygvirtmod_qemu(void); -# endif #else -# ifndef __CYGWIN__ -extern void initlibvirtmod_qemu(void); -# else -extern void initcygvirtmod_qemu(void); -# endif +extern PyObject *PyInit_cygvirtmod_qemu(void); #endif =20 #if 0 @@ -351,14 +343,13 @@ static PyMethodDef libvirtQemuMethods[] =3D { {NULL, NULL, 0, NULL} }; =20 -#if PY_MAJOR_VERSION > 2 static struct PyModuleDef moduledef =3D { PyModuleDef_HEAD_INIT, -# ifndef __CYGWIN__ +#ifndef __CYGWIN__ "libvirtmod_qemu", -# else +#else "cygvirtmod_qemu", -# endif +#endif NULL, -1, libvirtQemuMethods, @@ -369,11 +360,11 @@ static struct PyModuleDef moduledef =3D { }; =20 PyObject * -# ifndef __CYGWIN__ +#ifndef __CYGWIN__ PyInit_libvirtmod_qemu -# else +#else PyInit_cygvirtmod_qemu -# endif +#endif (void) { PyObject *module; @@ -385,25 +376,3 @@ PyInit_cygvirtmod_qemu =20 return module; } -#else /* ! PY_MAJOR_VERSION > 2 */ -void -# ifndef __CYGWIN__ -initlibvirtmod_qemu -# else -initcygvirtmod_qemu -# endif -(void) -{ - if (virInitialize() < 0) - return; - - /* initialize the python extension module */ - Py_InitModule((char *) -# ifndef __CYGWIN__ - "libvirtmod_qemu", -# else - "cygvirtmod_qemu", -# endif - libvirtQemuMethods); -} -#endif /* ! PY_MAJOR_VERSION > 2 */ diff --git a/libvirt-utils.c b/libvirt-utils.c index 78b94ca..d8ff11d 100644 --- a/libvirt-utils.c +++ b/libvirt-utils.c @@ -1,7 +1,7 @@ /* * libvirt-utils.c: misc helper APIs for python binding * - * Copyright (C) 2013 Red Hat, Inc. + * Copyright (C) 2013-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -274,11 +274,7 @@ setPyVirTypedParameter(PyObject *info, int nparams) { PyObject *key, *value; -#if PY_MAJOR_VERSION =3D=3D 2 && PY_MINOR_VERSION <=3D 4 - int pos =3D 0; -#else Py_ssize_t pos =3D 0; -#endif virTypedParameterPtr temp =3D NULL, ret =3D NULL; Py_ssize_t size; ssize_t i; @@ -416,13 +412,6 @@ virPyDictToTypedParamOne(virTypedParameterPtr *params, type =3D VIR_TYPED_PARAM_LLONG; else type =3D VIR_TYPED_PARAM_ULLONG; -#if PY_MAJOR_VERSION < 3 - } else if (PyInt_Check(value)) { - if (PyInt_AS_LONG(value) < 0) - type =3D VIR_TYPED_PARAM_LLONG; - else - type =3D VIR_TYPED_PARAM_ULLONG; -#endif } else if (PyFloat_Check(value)) { type =3D VIR_TYPED_PARAM_DOUBLE; } @@ -520,11 +509,7 @@ virPyDictToTypedParams(PyObject *dict, { PyObject *key; PyObject *value; -#if PY_MAJOR_VERSION =3D=3D 2 && PY_MINOR_VERSION <=3D 4 - int pos =3D 0; -#else Py_ssize_t pos =3D 0; -#endif virTypedParameterPtr params =3D NULL; int n =3D 0; int max =3D 0; diff --git a/libvirt-utils.h b/libvirt-utils.h index cc3d278..82f0af8 100644 --- a/libvirt-utils.h +++ b/libvirt-utils.h @@ -139,11 +139,7 @@ int virReallocN(void *ptrptr, size_t size, size_t coun= t) void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); =20 =20 -# if PY_MAJOR_VERSION > 2 -# define libvirt_PyString_Check PyUnicode_Check -# else -# define libvirt_PyString_Check PyString_Check -# endif +# define libvirt_PyString_Check PyUnicode_Check =20 =20 #define VIR_N_ELEMENTS(array) (sizeof(array) / sizeof(*(array))) diff --git a/sanitytest.py b/sanitytest.py index 0b415fd..1bedd55 100644 --- a/sanitytest.py +++ b/sanitytest.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 =20 import sys import lxml diff --git a/setup.py b/setup.py index 117f6ff..ea25dc0 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 =20 from distutils.core import setup, Extension, Command from distutils.command.build import build @@ -17,6 +17,10 @@ import re import shutil import time =20 +if sys.version_info[0] !=3D 3: + print("libvirt-python requires Python 3.x to build") + sys.exit(1) + MIN_LIBVIRT =3D "0.9.11" MIN_LIBVIRT_LXC =3D "1.0.2" =20 @@ -341,7 +345,7 @@ setup(name =3D 'libvirt-python', description =3D 'The libvirt virtualization API python binding', long_description =3D '''The libvirt-python package provides a module that permits appli= cations -written in the Python programming language to call the interface +written in the Python 3.x programming language to call the interface supplied by the libvirt library, to manage the virtualization capabilities of recent versions of Linux (and other OSes).''', license =3D 'LGPLv2+', @@ -362,7 +366,6 @@ of recent versions of Linux (and other OSes).''', "Intended Audience :: Developers", "License :: OSI Approved :: GNU Lesser General Public License v2= or later (LGPLv2+)", "Programming Language :: Python", - "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", ] ) diff --git a/typewrappers.c b/typewrappers.c index 2507859..3b1df87 100644 --- a/typewrappers.c +++ b/typewrappers.c @@ -2,141 +2,88 @@ * types.c: converter functions between the internal representation * and the Python objects * - * Copyright (C) 2005, 2007, 2012 Red Hat, Inc. + * Copyright (C) 2005-2019 Red Hat, Inc. * * Daniel Veillard */ =20 /* Horrible kludge to work around even more horrible name-space pollution - * via Python.h. That file includes /usr/include/python2.5/pyconfig*.h, - * which has over 180 autoconf-style HAVE_* definitions. Shame on t= hem. */ + * via Python.h. That file includes /usr/include/python3.x/pyconfig*.h, + * which has over 180 autoconf-style HAVE_* definitions. Shame on them. = */ #undef HAVE_PTHREAD_H =20 #include "typewrappers.h" #include "libvirt-utils.h" =20 -#ifndef Py_CAPSULE_H -typedef void(*PyCapsule_Destructor)(void *, void *); -#endif - static PyObject * libvirt_buildPyObject(void *cobj, const char *name, PyCapsule_Destructor destr) { - PyObject *ret; - -#ifdef Py_CAPSULE_H - ret =3D PyCapsule_New(cobj, name, destr); -#else - ret =3D PyCObject_FromVoidPtrAndDesc(cobj, (void *) name, destr); -#endif /* _TEST_CAPSULE */ - - return ret; + return PyCapsule_New(cobj, name, destr); } =20 PyObject * libvirt_intWrap(int val) { - PyObject *ret; -#if PY_MAJOR_VERSION > 2 - ret =3D PyLong_FromLong((long) val); -#else - ret =3D PyInt_FromLong((long) val); -#endif - return ret; + return PyLong_FromLong((long) val); } =20 PyObject * libvirt_uintWrap(uint val) { - PyObject *ret; -#if PY_MAJOR_VERSION > 2 - ret =3D PyLong_FromLong((long) val); -#else - ret =3D PyInt_FromLong((long) val); -#endif - return ret; + return PyLong_FromLong((long) val); } =20 PyObject * libvirt_longWrap(long val) { - PyObject *ret; - ret =3D PyLong_FromLong(val); - return ret; + return PyLong_FromLong(val); } =20 PyObject * libvirt_ulongWrap(unsigned long val) { - PyObject *ret; - ret =3D PyLong_FromLong(val); - return ret; + return PyLong_FromLong(val); } =20 PyObject * libvirt_longlongWrap(long long val) { - PyObject *ret; - ret =3D PyLong_FromLongLong(val); - return ret; + return PyLong_FromLongLong(val); } =20 PyObject * libvirt_ulonglongWrap(unsigned long long val) { - PyObject *ret; - ret =3D PyLong_FromUnsignedLongLong(val); - return ret; + return PyLong_FromUnsignedLongLong(val); } =20 PyObject * libvirt_charPtrSizeWrap(char *str, Py_ssize_t size) { - PyObject *ret; - if (str =3D=3D NULL) { return VIR_PY_NONE; } -#if PY_MAJOR_VERSION > 2 - ret =3D PyBytes_FromStringAndSize(str, size); -#else - ret =3D PyString_FromStringAndSize(str, size); -#endif - return ret; + return PyBytes_FromStringAndSize(str, size); } =20 PyObject * libvirt_charPtrWrap(char *str) { - PyObject *ret; - if (str =3D=3D NULL) { return VIR_PY_NONE; } -#if PY_MAJOR_VERSION > 2 - ret =3D PyUnicode_FromString(str); -#else - ret =3D PyString_FromString(str); -#endif - return ret; + return PyUnicode_FromString(str); } =20 PyObject * libvirt_constcharPtrWrap(const char *str) { - PyObject *ret; - if (str =3D=3D NULL) { return VIR_PY_NONE; } -#if PY_MAJOR_VERSION > 2 - ret =3D PyUnicode_FromString(str); -#else - ret =3D PyString_FromString(str); -#endif - return ret; + return PyUnicode_FromString(str); } =20 PyObject * @@ -163,11 +110,7 @@ libvirt_intUnwrap(PyObject *obj, * to C long type directly. If it is of PyLong_Type, PyInt_AsLong * will call PyLong_AsLong() to deal with it automatically. */ -#if PY_MAJOR_VERSION > 2 long_val =3D PyLong_AsLong(obj); -#else - long_val =3D PyInt_AsLong(obj); -#endif if ((long_val =3D=3D -1) && PyErr_Occurred()) return -1; =20 @@ -196,11 +139,7 @@ libvirt_uintUnwrap(PyObject *obj, return -1; } =20 -#if PY_MAJOR_VERSION > 2 long_val =3D PyLong_AsLong(obj); -#else - long_val =3D PyInt_AsLong(obj); -#endif if ((long_val =3D=3D -1) && PyErr_Occurred()) return -1; =20 @@ -269,14 +208,7 @@ libvirt_longlongUnwrap(PyObject *obj, return -1; } =20 -#if PY_MAJOR_VERSION =3D=3D 2 - /* If obj is of PyInt_Type, PyLong_AsLongLong - * will call PyInt_AsLong() to handle it automatically. - */ - if (PyInt_Check(obj) || PyLong_Check(obj)) -#else if (PyLong_Check(obj)) -#endif llong_val =3D PyLong_AsLongLong(obj); else PyErr_SetString(PyExc_TypeError, "an integer is required"); @@ -299,21 +231,7 @@ libvirt_ulonglongUnwrap(PyObject *obj, return -1; } =20 -#if PY_MAJOR_VERSION =3D=3D 2 - /* The PyLong_AsUnsignedLongLong doesn't check the type of - * obj, only accept argument of PyLong_Type, so we check it instead. - */ - if (PyInt_Check(obj)) { - long long llong_val =3D PyInt_AsLong(obj); - if (llong_val < 0) - PyErr_SetString(PyExc_OverflowError, - "negative Python int cannot be converted to C = unsigned long long"); - else - ullong_val =3D llong_val; - } else if (PyLong_Check(obj)) { -#else if (PyLong_Check(obj)) { -#endif ullong_val =3D PyLong_AsUnsignedLongLong(obj); } else { PyErr_SetString(PyExc_TypeError, "an integer is required"); @@ -367,9 +285,7 @@ int libvirt_charPtrUnwrap(PyObject *obj, char **str) { -#if PY_MAJOR_VERSION > 2 PyObject *bytes; -#endif const char *ret; *str =3D NULL; if (!obj) { @@ -377,21 +293,15 @@ libvirt_charPtrUnwrap(PyObject *obj, return -1; } =20 -#if PY_MAJOR_VERSION > 2 if (!(bytes =3D PyUnicode_AsUTF8String(obj))) return -1; ret =3D PyBytes_AsString(bytes); -#else - ret =3D PyString_AsString(obj); -#endif if (ret) { *str =3D strdup(ret); if (!*str) PyErr_NoMemory(); } -#if PY_MAJOR_VERSION > 2 Py_DECREF(bytes); -#endif return ret && *str ? 0 : -1; } =20 @@ -400,10 +310,6 @@ libvirt_charPtrSizeUnwrap(PyObject *obj, char **str, Py_ssize_t *size) { - int ret; -#if PY_MAJOR_VERSION =3D=3D 2 && PY_MINOR_VERSION <=3D 4 - int isize; -#endif *str =3D NULL; *size =3D 0; if (!obj) { @@ -411,18 +317,7 @@ libvirt_charPtrSizeUnwrap(PyObject *obj, return -1; } =20 -#if PY_MAJOR_VERSION > 2 - ret =3D PyBytes_AsStringAndSize(obj, str, size); -#else -# if PY_MINOR_VERSION <=3D 4 - ret =3D PyString_AsStringAndSize(obj, str, &isize); - *size =3D isize; -# else - ret =3D PyString_AsStringAndSize(obj, str, size); -# endif -#endif - - return ret; + return PyBytes_AsStringAndSize(obj, str, size); } =20 PyObject * diff --git a/typewrappers.h b/typewrappers.h index 486017a..fc923bf 100644 --- a/typewrappers.h +++ b/typewrappers.h @@ -22,11 +22,6 @@ # define ATTRIBUTE_UNUSED #endif =20 -/* Work around really old python. */ -#if PY_MAJOR_VERSION =3D=3D 2 && PY_MINOR_VERSION < 5 -typedef ssize_t Py_ssize_t; -#endif - #if !LIBVIR_CHECK_VERSION(4, 5, 0) typedef struct _virNWFilterBinding *virNWFilterBindingPtr; #endif --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list