diff --git a/src/aws_encryption_sdk/__init__.py b/src/aws_encryption_sdk/__init__.py index 0525f332d..661d41ee6 100644 --- a/src/aws_encryption_sdk/__init__.py +++ b/src/aws_encryption_sdk/__init__.py @@ -12,13 +12,13 @@ # language governing permissions and limitations under the License. """High level AWS Encryption SDK client functions.""" # Below are imported for ease of use by implementors - import warnings import attr from aws_encryption_sdk.caches.local import LocalCryptoMaterialsCache # noqa from aws_encryption_sdk.caches.null import NullCryptoMaterialsCache # noqa +from aws_encryption_sdk.compatability import _warn_deprecated_python from aws_encryption_sdk.exceptions import AWSEncryptionSDKClientError # noqa from aws_encryption_sdk.identifiers import Algorithm, CommitmentPolicy, __version__ # noqa from aws_encryption_sdk.internal.utils.signature import SignaturePolicy # noqa @@ -36,6 +36,8 @@ StreamEncryptor, ) +_warn_deprecated_python() + @attr.s(hash=True) class EncryptionSDKClientConfig(object): diff --git a/src/aws_encryption_sdk/compatability.py b/src/aws_encryption_sdk/compatability.py new file mode 100644 index 000000000..4dbc022d0 --- /dev/null +++ b/src/aws_encryption_sdk/compatability.py @@ -0,0 +1,39 @@ +# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). You +# may not use this file except in compliance with the License. A copy of +# the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file 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. +"""Contains logic for checking ESDK and Python Version""" +import sys +import warnings + +DEPRECATION_DATE_MAP = {"1.x": "2022-06-30", "2.x": "2022-07-01"} + + +def _warn_deprecated_python(): + """Template for deprecation of Python warning.""" + deprecated_versions = { + (2, 7): {"date": DEPRECATION_DATE_MAP["2.x"]}, + (3, 4): {"date": DEPRECATION_DATE_MAP["2.x"]}, + (3, 5): {"date": "2021-11-10"}, + } + py_version = (sys.version_info.major, sys.version_info.minor) + minimum_version = (3, 6) + + if py_version in deprecated_versions: + params = deprecated_versions[py_version] + warning = ( + "aws-encryption-sdk will no longer support Python {}.{} " + "starting {}. To continue receiving service updates, " + "bug fixes, and security updates please upgrade to Python {}.{} or " + "later. For more information, see SUPPORT_POLICY.rst: " + "https://github.com/aws/aws-encryption-sdk-python/blob/master/SUPPORT_POLICY.rst" + ).format(py_version[0], py_version[1], minimum_version[0], minimum_version[1], params["date"]) + warnings.warn(warning, DeprecationWarning) diff --git a/src/aws_encryption_sdk/streaming_client.py b/src/aws_encryption_sdk/streaming_client.py index ac215c259..54eb046d2 100644 --- a/src/aws_encryption_sdk/streaming_client.py +++ b/src/aws_encryption_sdk/streaming_client.py @@ -70,7 +70,7 @@ _LOGGER = logging.getLogger(__name__) -@attr.s(hash=True) +@attr.s(hash=True) # pylint: disable=too-many-instance-attributes @six.add_metaclass(abc.ABCMeta) class _ClientConfig(object): # pylint: disable=too-many-instance-attributes """Parent configuration object for StreamEncryptor and StreamDecryptor objects. diff --git a/test/pylintrc b/test/pylintrc index 21365a29e..ceff0ad13 100644 --- a/test/pylintrc +++ b/test/pylintrc @@ -5,6 +5,7 @@ disable = missing-docstring, # we don't write docstrings for tests bad-continuation, # we let black handle this ungrouped-imports, # we let isort handle this + wrong-import-order, # we let isort handle this abstract-class-instantiated, # we do this on purpose to test that they are enforced no-member, # raised on patched objects with mock checks no-self-use, # common pattern when using pytest classes: can be enabled once all tests are refactored to pytest functions @@ -24,6 +25,7 @@ disable = super-with-arguments, consider-using-f-string # disable until 2022-05-05; 6 months after 3.5 deprecation + [VARIABLES] additional-builtins = raw_input diff --git a/test/unit/test_compatability.py b/test/unit/test_compatability.py new file mode 100644 index 000000000..bf444052d --- /dev/null +++ b/test/unit/test_compatability.py @@ -0,0 +1,38 @@ +# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). You +# may not use this file except in compliance with the License. A copy of +# the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file 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. +"""Unit test suite for aws_encryption_sdk.compatability""" +import sys + +import mock +import pytest + +from aws_encryption_sdk.compatability import _warn_deprecated_python + +pytestmark = [pytest.mark.unit, pytest.mark.local] + + +class TestWarnDeprecatedPython: + def test_happy_version(self): + with mock.patch.object(sys, "version_info") as v_info: + v_info.major = 3 + v_info.minor = 6 + with pytest.warns(None) as record: + _warn_deprecated_python() + assert len(record) == 0 + + def test_below_warn(self): + with mock.patch.object(sys, "version_info") as v_info: + v_info.major = 2 + v_info.minor = 7 + with pytest.warns(DeprecationWarning): + _warn_deprecated_python()