Skip to content

Commit caa39b7

Browse files
authored
feat(compatability): Check Python Runtime (#372)
Issues a WARNING if the Python Version will become/is unsupported. Will start issuing WARNING for Python Version less than 3.6.
1 parent 39d98fb commit caa39b7

File tree

5 files changed

+83
-2
lines changed

5 files changed

+83
-2
lines changed

src/aws_encryption_sdk/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
# language governing permissions and limitations under the License.
1313
"""High level AWS Encryption SDK client functions."""
1414
# Below are imported for ease of use by implementors
15-
1615
import warnings
1716

1817
import attr
1918

2019
from aws_encryption_sdk.caches.local import LocalCryptoMaterialsCache # noqa
2120
from aws_encryption_sdk.caches.null import NullCryptoMaterialsCache # noqa
21+
from aws_encryption_sdk.compatability import _warn_deprecated_python
2222
from aws_encryption_sdk.exceptions import AWSEncryptionSDKClientError # noqa
2323
from aws_encryption_sdk.identifiers import Algorithm, CommitmentPolicy, __version__ # noqa
2424
from aws_encryption_sdk.internal.utils.signature import SignaturePolicy # noqa
@@ -36,6 +36,8 @@
3636
StreamEncryptor,
3737
)
3838

39+
_warn_deprecated_python()
40+
3941

4042
@attr.s(hash=True)
4143
class EncryptionSDKClientConfig(object):
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Contains logic for checking ESDK and Python Version"""
14+
import sys
15+
import warnings
16+
17+
DEPRECATION_DATE_MAP = {"1.x": "2022-06-30", "2.x": "2022-07-01"}
18+
19+
20+
def _warn_deprecated_python():
21+
"""Template for deprecation of Python warning."""
22+
deprecated_versions = {
23+
(2, 7): {"date": DEPRECATION_DATE_MAP["2.x"]},
24+
(3, 4): {"date": DEPRECATION_DATE_MAP["2.x"]},
25+
(3, 5): {"date": "2021-11-10"},
26+
}
27+
py_version = (sys.version_info.major, sys.version_info.minor)
28+
minimum_version = (3, 6)
29+
30+
if py_version in deprecated_versions:
31+
params = deprecated_versions[py_version]
32+
warning = (
33+
"aws-encryption-sdk will no longer support Python {}.{} "
34+
"starting {}. To continue receiving service updates, "
35+
"bug fixes, and security updates please upgrade to Python {}.{} or "
36+
"later. For more information, see SUPPORT_POLICY.rst: "
37+
"https://github.com/aws/aws-encryption-sdk-python/blob/master/SUPPORT_POLICY.rst"
38+
).format(py_version[0], py_version[1], minimum_version[0], minimum_version[1], params["date"])
39+
warnings.warn(warning, DeprecationWarning)

src/aws_encryption_sdk/streaming_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
_LOGGER = logging.getLogger(__name__)
7171

7272

73-
@attr.s(hash=True)
73+
@attr.s(hash=True) # pylint: disable=too-many-instance-attributes
7474
@six.add_metaclass(abc.ABCMeta)
7575
class _ClientConfig(object): # pylint: disable=too-many-instance-attributes
7676
"""Parent configuration object for StreamEncryptor and StreamDecryptor objects.

test/pylintrc

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ disable =
55
missing-docstring, # we don't write docstrings for tests
66
bad-continuation, # we let black handle this
77
ungrouped-imports, # we let isort handle this
8+
wrong-import-order, # we let isort handle this
89
abstract-class-instantiated, # we do this on purpose to test that they are enforced
910
no-member, # raised on patched objects with mock checks
1011
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 =
2425
super-with-arguments,
2526
consider-using-f-string # disable until 2022-05-05; 6 months after 3.5 deprecation
2627

28+
2729
[VARIABLES]
2830
additional-builtins = raw_input
2931

test/unit/test_compatability.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""Unit test suite for aws_encryption_sdk.compatability"""
14+
import sys
15+
16+
import mock
17+
import pytest
18+
19+
from aws_encryption_sdk.compatability import _warn_deprecated_python
20+
21+
pytestmark = [pytest.mark.unit, pytest.mark.local]
22+
23+
24+
class TestWarnDeprecatedPython:
25+
def test_happy_version(self):
26+
with mock.patch.object(sys, "version_info") as v_info:
27+
v_info.major = 3
28+
v_info.minor = 6
29+
with pytest.warns(None) as record:
30+
_warn_deprecated_python()
31+
assert len(record) == 0
32+
33+
def test_below_warn(self):
34+
with mock.patch.object(sys, "version_info") as v_info:
35+
v_info.major = 2
36+
v_info.minor = 7
37+
with pytest.warns(DeprecationWarning):
38+
_warn_deprecated_python()

0 commit comments

Comments
 (0)