diff --git a/src/dynamodb_encryption_sdk/__init__.py b/src/dynamodb_encryption_sdk/__init__.py index 7b5dba80..d1536792 100644 --- a/src/dynamodb_encryption_sdk/__init__.py +++ b/src/dynamodb_encryption_sdk/__init__.py @@ -11,6 +11,7 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. """DynamoDB Encryption Client.""" +from dynamodb_encryption_sdk.compatability import _warn_deprecated_python from dynamodb_encryption_sdk.encrypted.client import EncryptedClient from dynamodb_encryption_sdk.encrypted.item import ( decrypt_dynamodb_item, @@ -22,6 +23,8 @@ from dynamodb_encryption_sdk.encrypted.table import EncryptedTable from dynamodb_encryption_sdk.identifiers import __version__ +_warn_deprecated_python() + __all__ = ( "decrypt_dynamodb_item", "decrypt_python_item", diff --git a/src/dynamodb_encryption_sdk/compatability.py b/src/dynamodb_encryption_sdk/compatability.py new file mode 100644 index 00000000..b63781d1 --- /dev/null +++ b/src/dynamodb_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 the Python Version""" +import sys +import warnings + +DEPRECATION_DATE_MAP = {"1.x": "2022-07-08", "2.x": "2022-07-15"} + + +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-dynamodb-encryption 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-dynamodb-encryption-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/test/pylintrc b/test/pylintrc index 24de7029..f63b3263 100644 --- a/test/pylintrc +++ b/test/pylintrc @@ -10,6 +10,7 @@ disable = protected-access, # raised when calling _ methods redefined-outer-name, # raised when using pytest-mock unused-argument, # raised when patches and fixtures are needed but not called + no-self-use, # raised on Classes in tests used for logically grouping tests # All below are disabled because we need to support Python 2 useless-object-inheritance, raise-missing-from, diff --git a/test/unit/test_compatability.py b/test/unit/test_compatability.py new file mode 100644 index 00000000..a658d7b7 --- /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 dynamodb_encryption_sdk.compatability.""" +import sys + +import mock +import pytest + +from dynamodb_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()