THRIFT-3515 Python 2.6 compatibility and test on CI This closes #766
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/33744b05 Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/33744b05 Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/33744b05 Branch: refs/heads/master Commit: 33744b0524b7248dda9e9e544420d69c33d3a3aa Parents: 1d8e745 Author: Nobuaki Sukegawa <ns...@apache.org> Authored: Sun Jan 3 14:24:39 2016 +0900 Committer: Nobuaki Sukegawa <ns...@apache.org> Committed: Tue Jan 5 03:02:35 2016 +0900 ---------------------------------------------------------------------- .travis.yml | 6 +++ build/cmake/DefineOptions.cmake | 70 +++++++++++++++------------- build/cmake/DefinePlatformSpecifc.cmake | 0 build/docker/centos6/Dockerfile | 49 +++++++++++++++++++ build/docker/centos6/scripts/keepit | 1 + configure.ac | 2 +- lib/py/src/compat.py | 2 +- lib/py/src/protocol/TCompactProtocol.py | 4 +- lib/py/src/protocol/TJSONProtocol.py | 4 +- test/py/SerializationTest.py | 4 ++ 10 files changed, 103 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/33744b05/.travis.yml ---------------------------------------------------------------------- diff --git a/.travis.yml b/.travis.yml index 97440f3..88e9745 100644 --- a/.travis.yml +++ b/.travis.yml @@ -113,6 +113,12 @@ env: BUILD_ENV="-e CC=gcc -e CXX=g++" DISTRO=centos + - TEST_NAME="Python 2.6 (CentOS 6)" + BUILD_CMD="../cmake.sh" + BUILD_ARG="-DWITH_PYTHON=ON -DWITH_CPP=OFF -DWITH_JAVA=OFF -DWITH_HASKELL=OFF" + BUILD_ENV="-e CC=gcc -e CXX=g++" + DISTRO=centos6 + # Distribution - TEST_NAME="make dist" BUILD_CMD="../make-dist.sh" http://git-wip-us.apache.org/repos/asf/thrift/blob/33744b05/build/cmake/DefineOptions.cmake ---------------------------------------------------------------------- diff --git a/build/cmake/DefineOptions.cmake b/build/cmake/DefineOptions.cmake index 342e040..695a615 100644 --- a/build/cmake/DefineOptions.cmake +++ b/build/cmake/DefineOptions.cmake @@ -42,46 +42,50 @@ option(BUILD_LIBRARIES "Build Thrift libraries" ON) # C++ option(WITH_CPP "Build C++ Thrift library" ON) -find_package(Boost 1.53 QUIET) +if(WITH_CPP) + find_package(Boost 1.53 QUIET) + # NOTE: Currently the following options are C++ specific, + # but in future other libraries might reuse them. + # So they are not dependent on WITH_CPP but setting them without WITH_CPP currently + # has no effect. + if(ZLIB_LIBRARY) + # FindZLIB.cmake does not normalize path so we need to do it ourselves. + file(TO_CMAKE_PATH ${ZLIB_LIBRARY} ZLIB_LIBRARY) + endif() + find_package(ZLIB QUIET) + CMAKE_DEPENDENT_OPTION(WITH_ZLIB "Build with ZLIB support" ON + "ZLIB_FOUND" OFF) + find_package(Libevent QUIET) + CMAKE_DEPENDENT_OPTION(WITH_LIBEVENT "Build with libevent support" ON + "Libevent_FOUND" OFF) + find_package(Qt4 QUIET COMPONENTS QtCore QtNetwork) + CMAKE_DEPENDENT_OPTION(WITH_QT4 "Build with Qt4 support" ON + "QT4_FOUND" OFF) + find_package(Qt5 QUIET COMPONENTS Core Network) + CMAKE_DEPENDENT_OPTION(WITH_QT5 "Build with Qt5 support" ON + "Qt5_FOUND" OFF) + if(${WITH_QT4} AND ${WITH_QT5} AND ${CMAKE_MAJOR_VERSION} LESS 3) + # cmake < 3.0.0 causes conflict when building both Qt4 and Qt5 + set(WITH_QT4 OFF) + endif() + find_package(OpenSSL QUIET) + CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON + "OPENSSL_FOUND" OFF) + option(WITH_STDTHREADS "Build with C++ std::thread support" OFF) + CMAKE_DEPENDENT_OPTION(WITH_BOOSTTHREADS "Build with Boost threads support" OFF + "NOT WITH_STDTHREADS;Boost_FOUND" OFF) +endif() CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON "BUILD_LIBRARIES;WITH_CPP;Boost_FOUND" OFF) -# NOTE: Currently the following options are C++ specific, -# but in future other libraries might reuse them. -# So they are not dependent on WITH_CPP but setting them without WITH_CPP currently -# has no effect. -if(ZLIB_LIBRARY) - # FindZLIB.cmake does not normalize path so we need to do it ourselves. - file(TO_CMAKE_PATH ${ZLIB_LIBRARY} ZLIB_LIBRARY) -endif() -find_package(ZLIB QUIET) -CMAKE_DEPENDENT_OPTION(WITH_ZLIB "Build with ZLIB support" ON - "ZLIB_FOUND" OFF) -find_package(Libevent QUIET) -CMAKE_DEPENDENT_OPTION(WITH_LIBEVENT "Build with libevent support" ON - "Libevent_FOUND" OFF) -find_package(Qt4 QUIET COMPONENTS QtCore QtNetwork) -CMAKE_DEPENDENT_OPTION(WITH_QT4 "Build with Qt4 support" ON - "QT4_FOUND" OFF) -find_package(Qt5 QUIET COMPONENTS Core Network) -CMAKE_DEPENDENT_OPTION(WITH_QT5 "Build with Qt5 support" ON - "Qt5_FOUND" OFF) -if(${WITH_QT4} AND ${WITH_QT5} AND ${CMAKE_MAJOR_VERSION} LESS 3) - # cmake < 3.0.0 causes conflict when building both Qt4 and Qt5 - set(WITH_QT4 OFF) -endif() -find_package(OpenSSL QUIET) -CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON - "OPENSSL_FOUND" OFF) -option(WITH_STDTHREADS "Build with C++ std::thread support" OFF) -CMAKE_DEPENDENT_OPTION(WITH_BOOSTTHREADS "Build with Boost threads support" OFF - "NOT WITH_STDTHREADS;Boost_FOUND" OFF) - # C GLib option(WITH_C_GLIB "Build C (GLib) Thrift library" ON) -find_package(GLIB QUIET COMPONENTS gobject) +if(WITH_C_GLIB) + find_package(GLIB QUIET COMPONENTS gobject) +endif() CMAKE_DEPENDENT_OPTION(BUILD_C_GLIB "Build C (GLib) library" ON "BUILD_LIBRARIES;WITH_C_GLIB;GLIB_FOUND" OFF) + # Java option(WITH_JAVA "Build Java Thrift library" ON) if(ANDROID) http://git-wip-us.apache.org/repos/asf/thrift/blob/33744b05/build/cmake/DefinePlatformSpecifc.cmake ---------------------------------------------------------------------- diff --git a/build/cmake/DefinePlatformSpecifc.cmake b/build/cmake/DefinePlatformSpecifc.cmake old mode 100755 new mode 100644 http://git-wip-us.apache.org/repos/asf/thrift/blob/33744b05/build/docker/centos6/Dockerfile ---------------------------------------------------------------------- diff --git a/build/docker/centos6/Dockerfile b/build/docker/centos6/Dockerfile new file mode 100644 index 0000000..0e571c5 --- /dev/null +++ b/build/docker/centos6/Dockerfile @@ -0,0 +1,49 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Apache Thrift Docker build environment for Centos 6 +# +# This file is intended for testing old packages that are not available for +# latest Ubuntu LTS/Debian/CentOS. Currently, it is only used for Python 2.6. +# + +FROM centos:6 +MAINTAINER Apache Thrift <d...@thrift.apache.org> + +RUN yum install -y \ + autoconf \ + bison \ + bison-devel \ + clang \ + flex \ + gcc \ + gcc-c++ \ + git \ + libtool \ + m4 \ + make \ + perl \ + tar \ + python-devel \ + python-setuptools \ + python-twisted-web \ + python-six \ + && yum clean all + +# CMake +RUN curl -sSL https://cmake.org/files/v3.4/cmake-3.4.1.tar.gz | tar -xz && \ + cd cmake-3.4.1 && ./bootstrap && make -j4 && make install + +ENV THRIFT_ROOT /thrift +RUN mkdir -p $THRIFT_ROOT/src +COPY scripts $THRIFT_ROOT +WORKDIR $THRIFT_ROOT/src http://git-wip-us.apache.org/repos/asf/thrift/blob/33744b05/build/docker/centos6/scripts/keepit ---------------------------------------------------------------------- diff --git a/build/docker/centos6/scripts/keepit b/build/docker/centos6/scripts/keepit new file mode 100644 index 0000000..cb885df --- /dev/null +++ b/build/docker/centos6/scripts/keepit @@ -0,0 +1 @@ +keep it http://git-wip-us.apache.org/repos/asf/thrift/blob/33744b05/configure.ac ---------------------------------------------------------------------- diff --git a/configure.ac b/configure.ac index 27299b4..141b542 100755 --- a/configure.ac +++ b/configure.ac @@ -277,7 +277,7 @@ AM_CONDITIONAL(WITH_LUA, [test "$have_lua" = "yes"]) AX_THRIFT_LIB(python, [Python], yes) if test "$with_python" = "yes"; then AC_PATH_PROG([TRIAL], [trial]) - AM_PATH_PYTHON(2.4,, :) + AM_PATH_PYTHON(2.6,, :) if test -n "$TRIAL" && test "x$PYTHON" != "x" && test "x$PYTHON" != "x:" ; then have_python="yes" fi http://git-wip-us.apache.org/repos/asf/thrift/blob/33744b05/lib/py/src/compat.py ---------------------------------------------------------------------- diff --git a/lib/py/src/compat.py b/lib/py/src/compat.py index b2f47dc..06f672a 100644 --- a/lib/py/src/compat.py +++ b/lib/py/src/compat.py @@ -22,6 +22,6 @@ else: def str_to_binary(str_val): try: - return bytearray(str_val, 'utf8') + return bytes(str_val, 'utf8') except: return str_val http://git-wip-us.apache.org/repos/asf/thrift/blob/33744b05/lib/py/src/protocol/TCompactProtocol.py ---------------------------------------------------------------------- diff --git a/lib/py/src/protocol/TCompactProtocol.py b/lib/py/src/protocol/TCompactProtocol.py index a8b025a..6023066 100644 --- a/lib/py/src/protocol/TCompactProtocol.py +++ b/lib/py/src/protocol/TCompactProtocol.py @@ -56,7 +56,7 @@ def fromZigZag(n): def writeVarint(trans, n): - out = [] + out = bytearray() while True: if n & ~0x7f == 0: out.append(n) @@ -64,7 +64,7 @@ def writeVarint(trans, n): else: out.append((n & 0xff) | 0x80) n = n >> 7 - trans.write(bytearray(out)) + trans.write(bytes(out)) def readVarint(trans): http://git-wip-us.apache.org/repos/asf/thrift/blob/33744b05/lib/py/src/protocol/TJSONProtocol.py ---------------------------------------------------------------------- diff --git a/lib/py/src/protocol/TJSONProtocol.py b/lib/py/src/protocol/TJSONProtocol.py index acfce4a..3612e91 100644 --- a/lib/py/src/protocol/TJSONProtocol.py +++ b/lib/py/src/protocol/TJSONProtocol.py @@ -203,7 +203,7 @@ class TJSONProtocolBase(TProtocolBase): json_str.append('"') self.trans.write(str_to_binary(''.join(json_str))) - def writeJSONNumber(self, number, formatter='{}'): + def writeJSONNumber(self, number, formatter='{0}'): self.context.write() jsNumber = str(formatter.format(number)).encode('ascii') if self.context.escapeNum(): @@ -550,7 +550,7 @@ class TJSONProtocol(TJSONProtocolBase): def writeDouble(self, dbl): # 17 significant digits should be just enough for any double precision value. - self.writeJSONNumber(dbl, '{:.17g}') + self.writeJSONNumber(dbl, '{0:.17g}') def writeString(self, string): self.writeJSONString(string) http://git-wip-us.apache.org/repos/asf/thrift/blob/33744b05/test/py/SerializationTest.py ---------------------------------------------------------------------- diff --git a/test/py/SerializationTest.py b/test/py/SerializationTest.py index 99e0393..d4755cf 100755 --- a/test/py/SerializationTest.py +++ b/test/py/SerializationTest.py @@ -24,6 +24,7 @@ from DebugProtoTest.ttypes import CompactProtoTestStruct, Empty from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol, TCompactProtocol, TJSONProtocol from thrift.TSerialization import serialize, deserialize +import sys import unittest @@ -258,6 +259,9 @@ class AbstractTest(unittest.TestCase): self.assertTrue(len(rep) > 0) def testIntegerLimits(self): + if (sys.version_info[0] == 2 and sys.version_info[1] <= 6): + print('Skipping testIntegerLimits for Python 2.6') + return bad_values = [CompactProtoTestStruct(a_byte=128), CompactProtoTestStruct(a_byte=-129), CompactProtoTestStruct(a_i16=32768), CompactProtoTestStruct(a_i16=-32769), CompactProtoTestStruct(a_i32=2147483648), CompactProtoTestStruct(a_i32=-2147483649),