From c17c08dc24e1bb7fc9e2e36c53dc8da8c5471517 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Mon, 6 Mar 2023 00:18:10 -0800 Subject: [PATCH 1/3] Revert "Remove Python 2 Support (#162)" This reverts commit 19cc428f134f29bf00a2bcd6d99693cb0a313f0d. --- requirements.txt | 1 + setup.py | 2 +- tests/spec/test_hashable.py | 2 ++ tests/spec/test_struct.py | 3 ++- thriftrw/idl/lexer.py | 3 ++- tox.ini | 1 + 6 files changed, 9 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 337c5b2..3d8c4ae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ cython>=0.29.29 +six ply diff --git a/setup.py b/setup.py index 4248b94..1046928 100644 --- a/setup.py +++ b/setup.py @@ -150,7 +150,7 @@ def run(self): url='https://github.com/thriftrw/thriftrw-python', packages=find_packages(exclude=('tests', 'tests.*')), license='MIT', - install_requires=['ply'], + install_requires=['six', 'ply'], tests_require=['pytest', 'mock'], classifiers=[ 'Development Status :: 5 - Production/Stable', diff --git a/tests/spec/test_hashable.py b/tests/spec/test_hashable.py index a78d313..aa84c5d 100644 --- a/tests/spec/test_hashable.py +++ b/tests/spec/test_hashable.py @@ -20,6 +20,7 @@ from __future__ import absolute_import, unicode_literals, print_function import pytest +import six @pytest.mark.parametrize('name, src, kwargs', [ @@ -98,6 +99,7 @@ def test_hash_inequality(loads, name, src, kwargs1, kwargs2): assert hash(obj1) != hash(obj2) +@pytest.mark.skipif(six.PY2, reason="All Python 2 classes are hashable") @pytest.mark.parametrize('name, src, kwargs', [ ( 'Foo', ''' diff --git a/tests/spec/test_struct.py b/tests/spec/test_struct.py index 939b256..76ae27c 100644 --- a/tests/spec/test_struct.py +++ b/tests/spec/test_struct.py @@ -21,6 +21,7 @@ from __future__ import absolute_import, unicode_literals, print_function import pytest +import six from thriftrw.errors import ThriftCompilerError from thriftrw.spec.struct import StructTypeSpec @@ -321,7 +322,7 @@ def test_default_binary_value(loads): 1: optional binary field = ""; }''').Struct - assert isinstance(Struct().field, bytes) + assert isinstance(Struct().field, six.binary_type) def test_constructor_behavior(loads): diff --git a/thriftrw/idl/lexer.py b/thriftrw/idl/lexer.py index 126247d..91d9ec9 100644 --- a/thriftrw/idl/lexer.py +++ b/thriftrw/idl/lexer.py @@ -20,6 +20,7 @@ from __future__ import absolute_import, unicode_literals, print_function +import six from ply import lex from ..errors import ThriftParserError @@ -73,7 +74,7 @@ class LexerSpec(object): 'DUBCONSTANT', 'LITERAL', 'IDENTIFIER', - ) + tuple(map(str.upper, THRIFT_KEYWORDS)) + ) + tuple(map(six.text_type.upper, THRIFT_KEYWORDS)) t_ignore = ' \t\r' # whitespace diff --git a/tox.ini b/tox.ini index 45ee7dc..05bd8dc 100644 --- a/tox.ini +++ b/tox.ini @@ -37,5 +37,6 @@ basepython = python changedir = docs deps = sphinx + six ply commands = make html From d202ba87cdbe37a32965b40390a779168b00aa0d Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Mon, 6 Mar 2023 00:04:38 -0800 Subject: [PATCH 2/3] Test against python 2.7 --- .github/workflows/python.yml | 1 + tox.ini | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index d44f27f..e7f0241 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -14,6 +14,7 @@ jobs: strategy: matrix: python-version: + - '2.7' - '3.7' - '3.8' - '3.9' diff --git a/tox.ini b/tox.ini index 05bd8dc..5e39b41 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = 3.7,3.8,3.9,3.10,3.11,cover,flake8,docs +envlist = 2.7,3.7,3.8,3.9,3.10,3.11,cover,flake8,docs usedevelop = true [testenv] @@ -7,6 +7,7 @@ commands = python setup.py clean --all build_ext --force --inplace py.test -svv tests basepython = + 2.7: python2.7 3.7: python3.7 3.8: python3.8 3.9: python3.9 From 3e5c657f29fbe8ee9d2698421fdc9dd38e10d601 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Mon, 6 Mar 2023 00:29:47 -0800 Subject: [PATCH 3/3] Pin python 2.7 environment to older versions of dependencies --- tox.ini | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 5e39b41..de053ba 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,16 @@ basepython = 3.9: python3.9 3.10: python3.10 3.11: python3.11 -deps = -rrequirements-test.txt +deps = + 2.7: py-cpuinfo==8.0.0 + 2.7: pytest==4.6.11 + 2.7: pytest-cov==2.12.1 + 2.7: pytest-benchmark==3.4.1 + 3.7: -rrequirements-test.txt + 3.8: -rrequirements-test.txt + 3.9: -rrequirements-test.txt + 3.10: -rrequirements-test.txt + 3.11: -rrequirements-test.txt [testenv:cover] basepython = python