From f5e9c6535481e1ed70fa5e356668e5b0695481e0 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Mon, 2 Aug 2021 14:49:41 -0400 Subject: [PATCH] fix!: drop support for Python 2.7 (#43) Drop use of 'six' Drop use of 'mock' shim module Closes #42. --- setup.py | 11 ++------ test_utils/imports.py | 8 +++--- test_utils/retry.py | 11 ++++---- testing/constraints-3.6.txt | 3 +-- tests/unit/resources/bad_package/setup.py | 2 +- tests/unit/resources/good_package/setup.py | 2 +- tests/unit/test_lower_bound_checker.py | 30 +++++++++++----------- 7 files changed, 29 insertions(+), 38 deletions(-) diff --git a/setup.py b/setup.py index 376e03a..5829e13 100644 --- a/setup.py +++ b/setup.py @@ -40,19 +40,12 @@ entry_points={"console_scripts": scripts}, platforms="Posix; MacOS X; Windows", include_package_data=True, - install_requires=( - "google-auth >= 0.4.0", - "six>=1.9.0", - "click>=7.0.0", - "packaging>=19.0", - ), - python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*", + install_requires=("google-auth >= 0.4.0", "click>=7.0.0", "packaging>=19.0"), + python_requires=">=3.6", classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Operating System :: OS Independent", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", diff --git a/test_utils/imports.py b/test_utils/imports.py index 5991af7..46489b3 100644 --- a/test_utils/imports.py +++ b/test_utils/imports.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock -import six +import builtins +from unittest import mock def maybe_fail_import(predicate): @@ -28,11 +28,11 @@ def maybe_fail_import(predicate): Returns: A mock patcher object that can be used to enable patched import behavior. """ - orig_import = six.moves.builtins.__import__ + orig_import = builtins.__import__ def custom_import(name, globals=None, locals=None, fromlist=(), level=0): if predicate(name, globals, locals, fromlist, level): raise ImportError return orig_import(name, globals, locals, fromlist, level) - return mock.patch.object(six.moves.builtins, "__import__", new=custom_import) + return mock.patch.object(builtins, "__import__", new=custom_import) diff --git a/test_utils/retry.py b/test_utils/retry.py index 9880658..1e64324 100644 --- a/test_utils/retry.py +++ b/test_utils/retry.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import functools import time -import six - MAX_TRIES = 4 DELAY = 1 BACKOFF = 2 @@ -51,7 +50,7 @@ def __init__(self, max_tries=MAX_TRIES, delay=DELAY, backoff=BACKOFF, logger=Non self.max_tries = max_tries self.delay = delay self.backoff = backoff - self.logger = logger.warning if logger else six.print_ + self.logger = logger.warning if logger else print class RetryErrors(RetryBase): @@ -93,7 +92,7 @@ def __init__( self.error_predicate = error_predicate def __call__(self, to_wrap): - @six.wraps(to_wrap) + @functools.wraps(to_wrap) def wrapped_function(*args, **kwargs): tries = 0 while tries < self.max_tries: @@ -151,7 +150,7 @@ def __init__( self.result_predicate = result_predicate def __call__(self, to_wrap): - @six.wraps(to_wrap) + @functools.wraps(to_wrap) def wrapped_function(*args, **kwargs): tries = 0 while tries < self.max_tries: @@ -208,7 +207,7 @@ def __init__( def __call__(self, to_wrap): instance = to_wrap.__self__ # only instance methods allowed - @six.wraps(to_wrap) + @functools.wraps(to_wrap) def wrapped_function(*args, **kwargs): tries = 0 while tries < self.max_tries: diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 87fc11f..b0e36f6 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -1,5 +1,4 @@ click==7.0.0 google-auth==0.4.0 packaging==19.0 -six==1.9.0 -colorlog==3.0.0 \ No newline at end of file +colorlog==3.0.0 diff --git a/tests/unit/resources/bad_package/setup.py b/tests/unit/resources/bad_package/setup.py index dacf6d6..3daa33d 100644 --- a/tests/unit/resources/bad_package/setup.py +++ b/tests/unit/resources/bad_package/setup.py @@ -18,7 +18,7 @@ requirements = [ "requests", # no lower bound "packaging>=14.0, !=15.0, <22.0.0", # too complex for tool - "six<2.0.0", # no lower bound + "wheel<0.36.0", "click==7.0.0", ] diff --git a/tests/unit/resources/good_package/setup.py b/tests/unit/resources/good_package/setup.py index ec6da84..25c29ab 100644 --- a/tests/unit/resources/good_package/setup.py +++ b/tests/unit/resources/good_package/setup.py @@ -21,7 +21,7 @@ requirements = [ "requests>=1.0.0", "packaging>=14.0, <22.0.0", - "six<2.0.0, >=1.0.0", + "wheel<0.36.0, >=0.35.0", "click==7.0.0", ] diff --git a/tests/unit/test_lower_bound_checker.py b/tests/unit/test_lower_bound_checker.py index e177960..51da2e7 100644 --- a/tests/unit/test_lower_bound_checker.py +++ b/tests/unit/test_lower_bound_checker.py @@ -88,7 +88,7 @@ def test_update_constraints(): output = constraints_path.read_text().split("\n") - assert output == ["click==7.0.0", "grpcio==1.0.0", "packaging==14.0", "requests==1.0.0", "six==1.0.0",] + assert output == ["click==7.0.0", "grpcio==1.0.0", "packaging==14.0", "requests==1.0.0", "wheel==0.35.0",] @@ -96,7 +96,7 @@ def test_update_constraints_overwrites_existing_file(): constraints = [ "requests==1.0.0", "packaging==13.0", - "six==1.6.0", + "wheel==0.36.0", "click==5.0.0", ] with constraints_file(constraints) as c: @@ -107,14 +107,14 @@ def test_update_constraints_overwrites_existing_file(): assert result.exit_code == 0 output = c.read_text().split("\n") - assert output == ["click==7.0.0", "grpcio==1.0.0", "packaging==14.0", "requests==1.0.0", "six==1.0.0", + assert output == ["click==7.0.0", "grpcio==1.0.0", "packaging==14.0", "requests==1.0.0", "wheel==0.35.0", ] def test_update_constraints_with_setup_py_missing_lower_bounds(): constraints = [ "requests==1.0.0", "packaging==14.0", - "six==1.0.0", + "wheel==0.35.0", "click==7.0.0", ] with constraints_file(constraints) as c: @@ -126,7 +126,7 @@ def test_update_constraints_with_setup_py_missing_lower_bounds(): assert "setup.py is missing explicit lower bounds" in result.output invalid_pkg_list = parse_error_msg(result.output) - assert set(invalid_pkg_list) == {"requests", "packaging", "six"} + assert set(invalid_pkg_list) == {"requests", "packaging", "wheel"} @@ -134,7 +134,7 @@ def test_check(): constraints = [ "requests==1.0.0", "packaging==14.0", - "six==1.0.0", + "wheel==0.35.0", "click==7.0.0", "grpcio==1.0.0" ] @@ -150,7 +150,7 @@ def test_update_constraints_with_extra_constraints(): constraints = [ "requests==1.0.0", "packaging==14.0", - "six==1.0.0", + "wheel==0.35.0", "click==7.0.0", "grpcio==1.0.0", "pytest==6.0.0", # additional requirement @@ -182,7 +182,7 @@ def test_check_with_constraints_file_invalid_pins(): constraints = [ "requests==1.0.0", "packaging==14.0", - "six==1.0.0, <2.0.0dev", # should be == + "wheel==1.0.0, <2.0.0dev", # should be == "click>=7.0.0", # should be == ] with constraints_file(constraints) as c: @@ -194,14 +194,14 @@ def test_check_with_constraints_file_invalid_pins(): invalid_pkg_list = parse_error_msg(result.output) - assert set(invalid_pkg_list) == {"six", "click"} + assert set(invalid_pkg_list) == {"wheel", "click"} def test_check_with_constraints_file_missing_packages(): constraints = [ "requests==1.0.0", "packaging==14.0", - # missing 'six' and 'click' and extra 'grpcio' + # missing 'wheel' and 'click' and extra 'grpcio' ] with constraints_file(constraints) as c: result = RUNNER.invoke( @@ -211,14 +211,14 @@ def test_check_with_constraints_file_missing_packages(): assert result.exit_code == 2 invalid_pkg_list = parse_error_msg(result.output) - assert set(invalid_pkg_list) == {"six", "click", "grpcio"} + assert set(invalid_pkg_list) == {"wheel", "click", "grpcio"} def test_check_with_constraints_file_different_versions(): constraints = [ "requests==1.2.0", # setup.py has 1.0.0 "packaging==14.1", # setup.py has 14.0 - "six==1.4.0", # setup.py has 1.0.0 + "wheel==0.36.0", # setup.py has 0.35.0 "click==7.0.0", "grpcio==1.0.0" ] @@ -230,14 +230,14 @@ def test_check_with_constraints_file_different_versions(): assert result.exit_code == 2 invalid_pkg_list = parse_diff_versions_error_msg(result.output) - assert set(invalid_pkg_list) == {"requests", "packaging", "six"} + assert set(invalid_pkg_list) == {"requests", "packaging", "wheel"} def test_check_with_setup_py_missing_lower_bounds(): constraints = [ "requests==1.0.0", "packaging==14.0", - "six==1.0.0", + "wheel==1.0.0", "click==7.0.0", ] with constraints_file(constraints) as c: @@ -248,4 +248,4 @@ def test_check_with_setup_py_missing_lower_bounds(): assert result.exit_code == 2 invalid_pkg_list = parse_error_msg(result.output) - assert set(invalid_pkg_list) == {"requests", "packaging", "six"} + assert set(invalid_pkg_list) == {"requests", "packaging", "wheel"}