[libvirt] [PATCH python] Add python3 to the automated build and RPM

From: "Daniel P. Berrange" <berrange@redhat.com> This updates autobuild.sh to test the python3 build process. The RPM specfile is changed to build a libvirt-python3 RPM on Fedora > 18 Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- autobuild.sh | 6 ++++++ libvirt-python.spec.in | 57 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/autobuild.sh b/autobuild.sh index b3beaf1..c7d2661 100755 --- a/autobuild.sh +++ b/autobuild.sh @@ -13,6 +13,12 @@ python setup.py build python setup.py test python setup.py install --root="$AUTOBUILD_INSTALL_ROOT" +if test -f /usr/bin/python3 ; then + python3 setup.py build + python3 setup.py test + python3 setup.py install --root="$AUTOBUILD_INSTALL_ROOT" +fi + type -p /usr/bin/rpmbuild > /dev/null 2>&1 || exit 0 if [ -n "$AUTOBUILD_COUNTER" ]; then diff --git a/libvirt-python.spec.in b/libvirt-python.spec.in index 7c6257e..c61febc 100644 --- a/libvirt-python.spec.in +++ b/libvirt-python.spec.in @@ -1,5 +1,10 @@ -Summary: The libvirt virtualization API python binding +%global with_python3 0 +%if 0%{?fedora} > 18 +%global with_python3 1 +%endif + +Summary: The libvirt virtualization API python2 binding Name: libvirt-python Version: @PY_VERSION@ Release: 1%{?dist}%{?extra_release} @@ -9,6 +14,17 @@ License: LGPLv2+ Group: Development/Libraries BuildRequires: libvirt-devel >= @C_VERSION@ BuildRequires: python-devel +%if %{with_python3} +BuildRequires: python3-devel +%endif + +%if %{with_python3} +%package -n libvirt-python3 +Summary: The libvirt virtualization API python3 binding +Url: http://libvirt.org +License: LGPLv2+ +Group: Development/Libraries +%endif # Don't want provides for python shared objects %{?filter_provides_in: %filter_provides_in %{python_sitearch}/.*\.so} @@ -20,22 +36,49 @@ 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). +%if %{with_python3} +%description -n libvirt-python3 +The libvirt-python 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 + %prep %setup -q %build -CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build +CFLAGS="$RPM_OPT_FLAGS" %{__python2} setup.py build +%if %{with_python3} +CFLAGS="$RPM_OPT_FLAGS" %{__python3} setup.py build +%endif %install -%{__python} setup.py install --skip-build --root=%{buildroot} +%{__python2} setup.py install --skip-build --root=%{buildroot} +%if %{with_python3} +%{__python3} setup.py install --skip-build --root=%{buildroot} +%endif rm -f %{buildroot}%{_libdir}/python*/site-packages/*egg-info %files %defattr(-,root,root) %doc ChangeLog AUTHORS NEWS README COPYING COPYING.LESSER examples/ -%{_libdir}/python*/site-packages/libvirt.py* -%{_libdir}/python*/site-packages/libvirt_qemu.py* -%{_libdir}/python*/site-packages/libvirt_lxc.py* -%{_libdir}/python*/site-packages/libvirtmod* +%{_libdir}/python2*/site-packages/libvirt.py* +%{_libdir}/python2*/site-packages/libvirt_qemu.py* +%{_libdir}/python2*/site-packages/libvirt_lxc.py* +%{_libdir}/python2*/site-packages/libvirtmod* + +%if %{with_python3} +%files -n libvirt-python3 +%defattr(-,root,root) +%doc ChangeLog AUTHORS NEWS README COPYING COPYING.LESSER examples/ +%{_libdir}/python3*/site-packages/libvirt.py* +%{_libdir}/python3*/site-packages/libvirt_qemu.py* +%{_libdir}/python3*/site-packages/libvirt_lxc.py* +%{_libdir}/python3*/site-packages/__pycache__/libvirt.cpython-*.py* +%{_libdir}/python3*/site-packages/__pycache__/libvirt_qemu.cpython-*.py* +%{_libdir}/python3*/site-packages/__pycache__/libvirt_lxc.cpython-*.py* +%{_libdir}/python3*/site-packages/libvirtmod* +%endif %changelog -- 1.8.3.1

On 12/11/2013 09:31 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
This updates autobuild.sh to test the python3 build process. The RPM specfile is changed to build a libvirt-python3 RPM on Fedora > 18
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- autobuild.sh | 6 ++++++ libvirt-python.spec.in | 57 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 7 deletions(-)
+++ b/libvirt-python.spec.in @@ -1,5 +1,10 @@
-Summary: The libvirt virtualization API python binding +%global with_python3 0 +%if 0%{?fedora} > 18 +%global with_python3 1 +%endif
Is %global the right thing to use? Elsewhere we have just used %define when setting up a variable that conditionalizes the rest of the spec file.
%build -CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build +CFLAGS="$RPM_OPT_FLAGS" %{__python2} setup.py build
How far back can we assume that %{__python2} exists? Is it going to bite us on RHEL 6 (where I'm guessing there is just %{__python})?
+%if %{with_python3} +CFLAGS="$RPM_OPT_FLAGS" %{__python3} setup.py build +%endif
%install -%{__python} setup.py install --skip-build --root=%{buildroot} +%{__python2} setup.py install --skip-build --root=%{buildroot}
More use of %{__python2}. Everything else looks okay to me, although I did not actually do any testing of the rpms. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Wed, Dec 11, 2013 at 01:01:03PM -0700, Eric Blake wrote:
On 12/11/2013 09:31 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
This updates autobuild.sh to test the python3 build process. The RPM specfile is changed to build a libvirt-python3 RPM on Fedora > 18
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- autobuild.sh | 6 ++++++ libvirt-python.spec.in | 57 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 7 deletions(-)
+++ b/libvirt-python.spec.in @@ -1,5 +1,10 @@
-Summary: The libvirt virtualization API python binding +%global with_python3 0 +%if 0%{?fedora} > 18 +%global with_python3 1 +%endif
Is %global the right thing to use? Elsewhere we have just used %define when setting up a variable that conditionalizes the rest of the spec file.
Oh I copied this from another Fedora spec, but this won't work on rhel5, so should stick with %define
%build -CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build +CFLAGS="$RPM_OPT_FLAGS" %{__python2} setup.py build
How far back can we assume that %{__python2} exists? Is it going to bite us on RHEL 6 (where I'm guessing there is just %{__python})?
It bites on RHEL-5, so i'll use plain %{__python} 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 :|

On Wed, Dec 11, 2013 at 04:31:46PM +0000, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
This updates autobuild.sh to test the python3 build process. The RPM specfile is changed to build a libvirt-python3 RPM on Fedora > 18
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- autobuild.sh | 6 ++++++ libvirt-python.spec.in | 57 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 7 deletions(-)
diff --git a/autobuild.sh b/autobuild.sh index b3beaf1..c7d2661 100755 --- a/autobuild.sh +++ b/autobuild.sh @@ -13,6 +13,12 @@ python setup.py build python setup.py test python setup.py install --root="$AUTOBUILD_INSTALL_ROOT"
I haven't tested it, but shouldn't these lines ^^, and others similar to them, be changed to "python2" in case my default python version is 3? And if those "python2" are checked as well, it would be usable even without python2. Or just use %{__python2} and %{__python3} as Eric suggested. Martin

On Thu, Dec 12, 2013 at 08:59:33AM +0100, Martin Kletzander wrote:
On Wed, Dec 11, 2013 at 04:31:46PM +0000, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
This updates autobuild.sh to test the python3 build process. The RPM specfile is changed to build a libvirt-python3 RPM on Fedora > 18
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- autobuild.sh | 6 ++++++ libvirt-python.spec.in | 57 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 56 insertions(+), 7 deletions(-)
diff --git a/autobuild.sh b/autobuild.sh index b3beaf1..c7d2661 100755 --- a/autobuild.sh +++ b/autobuild.sh @@ -13,6 +13,12 @@ python setup.py build python setup.py test python setup.py install --root="$AUTOBUILD_INSTALL_ROOT"
I haven't tested it, but shouldn't these lines ^^, and others similar to them, be changed to "python2" in case my default python version is 3? And if those "python2" are checked as well, it would be usable even without python2.
Yes, we should use python2
Or just use %{__python2} and %{__python3} as Eric suggested.
Those macros only work in RPM, not autobuild.sh 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 :|

On 12/12/2013 04:19 AM, Daniel P. Berrange wrote:
+++ b/autobuild.sh @@ -13,6 +13,12 @@ python setup.py build python setup.py test python setup.py install --root="$AUTOBUILD_INSTALL_ROOT"
I haven't tested it, but shouldn't these lines ^^, and others similar to them, be changed to "python2" in case my default python version is 3? And if those "python2" are checked as well, it would be usable even without python2.
Yes, we should use python2
But does 'python2' exist in PATH on RHEL5? You have to be careful that whatever solution you have works on systems with only one python installed (whether that be old systems with python 2, or bleeding edge systems with _only_ python 3). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Thu, Dec 12, 2013 at 12:29:34PM -0700, Eric Blake wrote:
On 12/12/2013 04:19 AM, Daniel P. Berrange wrote:
+++ b/autobuild.sh @@ -13,6 +13,12 @@ python setup.py build python setup.py test python setup.py install --root="$AUTOBUILD_INSTALL_ROOT"
I haven't tested it, but shouldn't these lines ^^, and others similar to them, be changed to "python2" in case my default python version is 3? And if those "python2" are checked as well, it would be usable even without python2.
Yes, we should use python2
But does 'python2' exist in PATH on RHEL5? You have to be careful that whatever solution you have works on systems with only one python installed (whether that be old systems with python 2, or bleeding edge systems with _only_ python 3).
Yes, it is. Python started to use these names quite a long time ago. We could even build with different python 2 versions (python2.6, python2.7, etc.) which are properly instantiated, I believe, in all stable to modern distros. Running any versioned binary should be checked for anyway, so we don't end up in a situation where we're calling one that doesn't exist, IMHO. Martin

On Thu, Dec 12, 2013 at 12:29:34PM -0700, Eric Blake wrote:
On 12/12/2013 04:19 AM, Daniel P. Berrange wrote:
+++ b/autobuild.sh @@ -13,6 +13,12 @@ python setup.py build python setup.py test python setup.py install --root="$AUTOBUILD_INSTALL_ROOT"
I haven't tested it, but shouldn't these lines ^^, and others similar to them, be changed to "python2" in case my default python version is 3? And if those "python2" are checked as well, it would be usable even without python2.
Yes, we should use python2
But does 'python2' exist in PATH on RHEL5? You have to be careful that whatever solution you have works on systems with only one python installed (whether that be old systems with python 2, or bleeding edge systems with _only_ python 3).
Yes, I checked RHEL5 for this. It has python2 in /usr/bin 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 :|
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Martin Kletzander