Skip to content

Commit

Permalink
fix!: drop support for Python 2.7 (#43)
Browse files Browse the repository at this point in the history
Drop use of 'six'

Drop use of 'mock' shim module

Closes #42.
  • Loading branch information
tseaver committed Aug 2, 2021
1 parent 284a721 commit f5e9c65
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 38 deletions.
11 changes: 2 additions & 9 deletions setup.py
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions test_utils/imports.py
Expand Up @@ -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):
Expand All @@ -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)
11 changes: 5 additions & 6 deletions test_utils/retry.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions 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
colorlog==3.0.0
2 changes: 1 addition & 1 deletion tests/unit/resources/bad_package/setup.py
Expand Up @@ -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",
]

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/resources/good_package/setup.py
Expand Up @@ -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",
]

Expand Down
30 changes: 15 additions & 15 deletions tests/unit/test_lower_bound_checker.py
Expand Up @@ -88,15 +88,15 @@ 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",]



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:
Expand All @@ -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:
Expand All @@ -126,15 +126,15 @@ 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"}



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"
]
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand All @@ -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"
]
Expand All @@ -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:
Expand All @@ -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"}

0 comments on commit f5e9c65

Please sign in to comment.