Skip to content

Commit

Permalink
feat(compatability): Check Python Runtime (#372)
Browse files Browse the repository at this point in the history
Issues a WARNING if the Python Version will become/is unsupported.
Will start issuing WARNING for Python Version less than 3.6.
  • Loading branch information
texastony committed Nov 8, 2021
1 parent 39d98fb commit caa39b7
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/aws_encryption_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +36,8 @@
StreamEncryptor,
)

_warn_deprecated_python()


@attr.s(hash=True)
class EncryptionSDKClientConfig(object):
Expand Down
39 changes: 39 additions & 0 deletions src/aws_encryption_sdk/compatability.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/aws_encryption_sdk/streaming_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions test/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
38 changes: 38 additions & 0 deletions test/unit/test_compatability.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit caa39b7

Please sign in to comment.