From 89fdf9dbcbf2dd7a82d67a1ec9e445a020afa5b0 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Fri, 6 Jan 2023 12:07:20 +0000 Subject: [PATCH] Remove Py3.6 support (#5818) --- .github/workflows/build.yml | 15 ++++++------ codecov.yml | 2 +- moto/core/models.py | 2 +- moto/dynamodb/models/__init__.py | 2 -- moto/iam/models.py | 6 +---- setup.py | 6 ++--- tests/test_amp/test_amp_logging_config.py | 5 ---- tests/test_ec2/test_customer_gateways.py | 7 ------ tests/test_ec2/test_vpcs.py | 13 ---------- tests/test_efs/test_mount_target.py | 30 ++--------------------- tests/test_iam/test_iam.py | 10 -------- 11 files changed, 14 insertions(+), 84 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 77448df39..7b3ceff72 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,11 +5,10 @@ on: [push, pull_request] jobs: cache: name: Caching - # Change to ubuntu-latest after dropping Py3.6 - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: matrix: - python-version: [ 3.6, 3.7, 3.8, 3.9, "3.10", "3.11" ] + python-version: [ 3.7, 3.8, 3.9, "3.10", "3.11" ] steps: - uses: actions/checkout@v3 @@ -42,7 +41,7 @@ jobs: needs: cache strategy: matrix: - python-version: [3.7] + python-version: [3.9] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} @@ -73,12 +72,12 @@ jobs: test: name: Unit test - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest needs: lint strategy: fail-fast: false matrix: - python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11"] + python-version: [3.7, 3.8, 3.9, "3.10", "3.11"] steps: - uses: actions/checkout@v3 @@ -117,12 +116,12 @@ jobs: testserver: name: Unit tests in Server Mode - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest needs: lint strategy: fail-fast: false matrix: - python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11"] + python-version: [3.7, 3.8, 3.9, "3.10", "3.11"] steps: - uses: actions/checkout@v3 diff --git a/codecov.yml b/codecov.yml index 69c33d4f8..750eb3b17 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,7 +1,7 @@ codecov: notify: # Leave a GitHub comment after all builds have passed - after_n_builds: 12 + after_n_builds: 10 coverage: status: project: diff --git a/moto/core/models.py b/moto/core/models.py index a0789bb5a..8a84c24fa 100644 --- a/moto/core/models.py +++ b/moto/core/models.py @@ -99,7 +99,7 @@ class BaseMockAWS: try: self.default_session_mock.stop() except RuntimeError: - # We only need to check for this exception in Python 3.6 and 3.7 + # We only need to check for this exception in Python 3.7 # https://bugs.python.org/issue36366 pass self.unmock_env_variables() diff --git a/moto/dynamodb/models/__init__.py b/moto/dynamodb/models/__init__.py index cd06d539b..bc915da4c 100644 --- a/moto/dynamodb/models/__init__.py +++ b/moto/dynamodb/models/__init__.py @@ -1351,8 +1351,6 @@ class DynamoDBBackend(BaseBackend): gsi_to_create, table.table_key_attrs ) - # in python 3.6, dict.values() returns a dict_values object, but we expect it to be a list in other - # parts of the codebase table.global_indexes = list(gsis_by_name.values()) return table diff --git a/moto/iam/models.py b/moto/iam/models.py index 5a23df68b..6ca24dda0 100644 --- a/moto/iam/models.py +++ b/moto/iam/models.py @@ -1,7 +1,6 @@ import base64 import os import string -import sys from datetime import datetime import json import re @@ -2399,10 +2398,7 @@ class IAMBackend(BaseBackend): # Validate the signing cert: try: - if sys.version_info < (3, 0): - data = bytes(body) - else: - data = bytes(body, "utf8") + data = bytes(body, "utf8") x509.load_pem_x509_certificate(data, default_backend()) diff --git a/setup.py b/setup.py index 976dcbd28..76bff66be 100755 --- a/setup.py +++ b/setup.py @@ -45,7 +45,6 @@ _dep_python_jose = "python-jose[cryptography]>=3.1.0,<4.0.0" _dep_python_jose_ecdsa_pin = ( "ecdsa!=0.15" # https://github.com/spulec/moto/pull/3263#discussion_r477404984 ) -_dep_dataclasses = "dataclasses; python_version < '3.7'" _dep_docker = "docker>=2.5.1" _dep_graphql = "graphql-core" _dep_jsondiff = "jsondiff>=1.1.2" @@ -96,7 +95,7 @@ extras_per_service.update( "ses": [], "sns": [], "sqs": [], - "ssm": [_dep_PyYAML, _dep_dataclasses], + "ssm": [_dep_PyYAML], # XRay module uses pkg_resources, but doesn't have an explicit # dependency listed. This should be fixed in the next version: # https://github.com/aws/aws-xray-sdk-python/issues/305 @@ -137,7 +136,7 @@ setup( url="https://github.com/spulec/moto", entry_points={"console_scripts": ["moto_server = moto.server:main"]}, packages=find_packages(exclude=("tests", "tests.*")), - python_requires=">=3.6", + python_requires=">=3.7", install_requires=install_requires, extras_require=extras_require, include_package_data=True, @@ -145,7 +144,6 @@ setup( test_suite="tests", classifiers=[ "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", diff --git a/tests/test_amp/test_amp_logging_config.py b/tests/test_amp/test_amp_logging_config.py index ba82539e3..5d952a4ab 100644 --- a/tests/test_amp/test_amp_logging_config.py +++ b/tests/test_amp/test_amp_logging_config.py @@ -1,5 +1,4 @@ import boto3 -import sys import unittest from moto import mock_amp @@ -7,10 +6,6 @@ from moto import mock_amp @mock_amp class TestAmpLoggingConfig(unittest.TestCase): def setUp(self) -> None: - if sys.version_info < (3, 7): - raise unittest.SkipTest( - "Cannot test this in Py3.6; outdated botocore dependencies do not yet support this feature" - ) self.client = boto3.client("amp", region_name="us-east-2") workspace = self.client.create_workspace(alias="test", tags={"t": "v"}) diff --git a/tests/test_ec2/test_customer_gateways.py b/tests/test_ec2/test_customer_gateways.py index 5a9a1edc1..7b5f17da5 100644 --- a/tests/test_ec2/test_customer_gateways.py +++ b/tests/test_ec2/test_customer_gateways.py @@ -1,11 +1,9 @@ import boto3 import pytest import sure # noqa # pylint: disable=unused-import -import sys from botocore.exceptions import ClientError from moto import mock_ec2 -from unittest import SkipTest @mock_ec2 @@ -21,11 +19,6 @@ def test_create_customer_gateways(): @mock_ec2 def test_create_customer_gateways_using_publicip_argument(): - version_info = sys.version_info - if version_info.major == 3 and version_info.minor <= 6: - raise SkipTest( - "Py 3.6 has an older versions of botocore, and does not support the IpAddress-argument" - ) ec2 = boto3.client("ec2", region_name="us-east-1") # The PublicIp-argument is deprecated, but should still be supported by Moto diff --git a/tests/test_ec2/test_vpcs.py b/tests/test_ec2/test_vpcs.py index 1c7966e45..f7c8759a6 100644 --- a/tests/test_ec2/test_vpcs.py +++ b/tests/test_ec2/test_vpcs.py @@ -5,7 +5,6 @@ import boto3 import sure # noqa # pylint: disable=unused-import import random -import sys from moto import mock_ec2, settings from unittest import SkipTest @@ -361,10 +360,6 @@ def test_vpc_get_by_tag_value_subset(): @mock_ec2 def test_default_vpc(): - if sys.version_info < (3, 7): - raise SkipTest( - "Cannot test this in Py3.6; outdated botocore dependencies do not have all regions" - ) ec2 = boto3.resource("ec2", region_name="us-west-1") # Create the default VPC @@ -392,10 +387,6 @@ def test_default_vpc(): @mock_ec2 def test_non_default_vpc(): - if sys.version_info < (3, 7): - raise SkipTest( - "Cannot test this in Py3.6; outdated botocore dependencies do not have all regions" - ) ec2 = boto3.resource("ec2", region_name="us-west-1") # Create the default VPC - this already exists when backend instantiated! @@ -512,10 +503,6 @@ def test_vpc_modify_enable_dns_hostnames(): @mock_ec2 def test_vpc_modify_enable_network_address_usage_metrics(): - if sys.version_info < (3, 7): - raise SkipTest( - "Cannot test this in Py3.6; outdated botocore dependencies do not have all regions" - ) ec2 = boto3.resource("ec2", region_name="us-west-1") # Create the default VPC diff --git a/tests/test_efs/test_mount_target.py b/tests/test_efs/test_mount_target.py index 385f3b6ff..b5f1209b0 100644 --- a/tests/test_efs/test_mount_target.py +++ b/tests/test_efs/test_mount_target.py @@ -1,5 +1,4 @@ import re -import sys from ipaddress import IPv4Network import pytest @@ -10,31 +9,6 @@ from tests.test_efs.junk_drawer import has_status_code from . import fixture_ec2, fixture_efs # noqa # pylint: disable=unused-import -# Handle the fact that `subnet_of` is not a feature before 3.7. -# Source for alternative version: https://github.com/python/cpython/blob/v3.7.0/Lib/ipaddress.py#L976 -# Discovered via: https://stackoverflow.com/questions/35115138/how-do-i-check-if-a-network-is-contained-in-another-network-in-python -if sys.version_info.major >= 3 and sys.version_info.minor >= 7: - - def is_subnet_of(a, b): - return a.subnet_of(b) - -else: - - def is_subnet_of(a, b): - try: - # Always false if one is v4 and the other is v6. - if a._version != b._version: - raise TypeError(f"{a} and {b} are not of the same version") - return ( - b.network_address <= a.network_address - and b.broadcast_address >= a.broadcast_address - ) - except AttributeError: - raise TypeError( - f"Unable to test subnet containment " f"between {a} and {b}" - ) - - @pytest.fixture(scope="function", name="file_system") def fixture_file_system(efs): create_fs_resp = efs.create_file_system(CreationToken="foobarbaz") @@ -69,8 +43,8 @@ def test_create_mount_target_minimal_correct_use(efs, file_system, subnet): assert create_mt_resp["AvailabilityZoneName"] == subnet["AvailabilityZone"] assert create_mt_resp["VpcId"] == subnet["VpcId"] assert create_mt_resp["SubnetId"] == subnet_id - assert is_subnet_of( - IPv4Network(create_mt_resp["IpAddress"]), IPv4Network(subnet["CidrBlock"]) + assert IPv4Network(create_mt_resp["IpAddress"]).subnet_of( + IPv4Network(subnet["CidrBlock"]) ) assert create_mt_resp["FileSystemId"] == file_system_id assert create_mt_resp["OwnerId"] == ACCOUNT_ID diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index f5a7ff193..bbc8f6ac3 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -1,5 +1,4 @@ import json -import sys import boto3 import csv @@ -16,7 +15,6 @@ import pytest from datetime import datetime from uuid import uuid4 from urllib import parse -from unittest import SkipTest from moto.s3.responses import DEFAULT_REGION_NAME @@ -3782,10 +3780,6 @@ def test_role_config_dict(): @mock_iam @mock_config def test_role_config_client(): - if sys.version_info < (3, 7): - raise SkipTest( - "Cannot test this in Py3.6; outdated botocore dependencies do not have all regions" - ) from moto.iam.utils import random_role_id CONFIG_REGIONS = boto3.Session().get_available_regions("config") @@ -4230,10 +4224,6 @@ def test_policy_config_dict(): @mock_iam @mock_config def test_policy_config_client(): - if sys.version_info < (3, 7): - raise SkipTest( - "Cannot test this in Py3.6; outdated botocore dependencies do not have all regions" - ) from moto.iam.utils import random_policy_id CONFIG_REGIONS = boto3.Session().get_available_regions("config")