add conditional build support for Python 3

This commit is contained in:
Joe Orton 2018-03-28 11:57:17 +01:00
parent 6b79bd116e
commit 92e90eb897
2 changed files with 91 additions and 2 deletions

View File

@ -0,0 +1,66 @@
From 17c92e43fda114bf5341e51d752e882238b8fe8c Mon Sep 17 00:00:00 2001
From: Nils Goroll <nils.goroll@uplex.de>
Date: Thu, 5 Oct 2017 13:39:23 +0200
Subject: [PATCH] hack up vsctool to work with python 2 and 3
StringIO does not exist any more in python3, yet requiring 2.7 would
not pave the path forward, so try to be compatible with both.
Works for me on Python 2.7.9 and Python 3.4
I would appreciate if someone more fluent in serpentinous programming
language reviewed and/or rewrote this.
---
lib/libvcc/vsctool.py | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/lib/libvcc/vsctool.py b/lib/libvcc/vsctool.py
index 854968e3b..829c6e518 100644
--- a/lib/libvcc/vsctool.py
+++ b/lib/libvcc/vsctool.py
@@ -37,7 +37,10 @@
import json
import sys
import gzip
-import StringIO
+try:
+ import StringIO
+except ImportError:
+ import io
import collections
import struct
@@ -54,9 +57,22 @@
"format": [ "integer", FORMATS],
}
+# http://python3porting.com/problems.html#bytes-strings-and-unicode
+if sys.version_info < (3,):
+ def b(x):
+ return x
+else:
+ import codecs
+ def b(x):
+ return codecs.latin_1_encode(x)[0]
+
def gzip_str(s):
- out = StringIO.StringIO()
- gzip.GzipFile(fileobj=out, mode="w").write(s)
+ try:
+ out = StringIO.StringIO()
+ except NameError:
+ out = io.BytesIO()
+
+ gzip.GzipFile(fileobj=out, mode="w").write(b(s))
out.seek(4)
out.write(struct.pack("<L", 0x12bfd58))
return out.getvalue()
@@ -285,7 +301,7 @@ class rst_vsc(directive):
def __init__(self, s):
super(rst_vsc, self).__init__(s)
- for i,v in PARAMS.iteritems():
+ for i,v in PARAMS.items():
if v is not True:
self.do_default(i, v[0], v[1])

View File

@ -14,10 +14,17 @@
%define commit1 5b976190ce9e0720f1eee6e9eaccd8a15eaa498d
%global shortcommit1 %(c=%{commit1}; echo ${c:0:7})
%bcond_without python2
%bcond_with python3
%if %{with python2} == %{with python3}
%error Pick exactly one Python version
%endif
Summary: High-performance HTTP accelerator
Name: varnish
Version: 5.2.1
Release: 4%{?v_rc}%{?dist}.1
Release: 5%{?v_rc}%{?dist}
License: BSD
Group: System Environment/Daemons
URL: http://www.varnish-cache.org/
@ -26,14 +33,18 @@ Source1: https://github.com/varnishcache/pkg-varnish-cache/archive/%{commit1}.ta
Patch1: varnish-5.1.1.fix_ld_library_path_in_doc_build.patch
Patch4: varnish-4.0.3_fix_varnish4_selinux.el6.patch
Patch6: varnish-4.1.0.fix_find-provides.patch
Patch8: varnish-5.2.1-python3.patch
Patch9: varnish-5.1.1.fix_python_version.patch
Patch10: vsv00002_test.patch
%if %{with python3}
BuildRequires: python3-sphinx, python3-docutils
%else
%if 0%{?rhel} >= 6
BuildRequires: python-sphinx
%endif
BuildRequires: python-docutils
%endif
BuildRequires: ncurses-devel
BuildRequires: groff
BuildRequires: pcre-devel
@ -104,7 +115,11 @@ Summary: Development files for %{name}-libs
Group: Development/Libraries
BuildRequires: ncurses-devel
Requires: varnish-libs = %{version}-%{release}
%if %{with python3}
Requires: python3
%else
Requires: python
%endif
Provides: varnish-libs-devel = %{version}-%{release}
Obsoletes: varnish-libs-devel
@ -139,6 +154,7 @@ ln -s pkg-varnish-cache-%{commit1}/debian debian
%patch9 -p0
%endif
%patch6 -p0
%patch8 -p1
%patch10 -p0
%build
@ -193,7 +209,11 @@ make %{?_smp_mflags} V=1
sed -i 's,User=varnishlog,User=varnish,g;' redhat/varnishncsa.service
# Explicit python, please
%if %{with python2}
sed -i 's/env python/python2/g;' lib/libvcc/vmodtool.py
%else
sed -i 's/env python/python3/g;' lib/libvcc/vmodtool.py
%endif
# Clean up the sphinx documentation
rm -rf doc/sphinx/build/html/_sources
@ -402,6 +422,9 @@ fi
%endif
%changelog
* Wed Mar 28 2018 Joe Orton <jorton@redhat.com> - 5.2.1-5
- add conditional build support for Python 3
* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 5.2.1-4.1
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild