From 92e90eb897370221805585c32fa25cdba255e3d9 Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Wed, 28 Mar 2018 11:57:17 +0100 Subject: [PATCH] add conditional build support for Python 3 --- varnish-5.2.1-python3.patch | 66 +++++++++++++++++++++++++++++++++++++ varnish.spec | 27 +++++++++++++-- 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 varnish-5.2.1-python3.patch diff --git a/varnish-5.2.1-python3.patch b/varnish-5.2.1-python3.patch new file mode 100644 index 0000000..f83385a --- /dev/null +++ b/varnish-5.2.1-python3.patch @@ -0,0 +1,66 @@ +From 17c92e43fda114bf5341e51d752e882238b8fe8c Mon Sep 17 00:00:00 2001 +From: Nils Goroll +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("= 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 - 5.2.1-5 +- add conditional build support for Python 3 + * Fri Feb 09 2018 Fedora Release Engineering - 5.2.1-4.1 - Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild