Skip to content

Commit d7c8d37

Browse files
authored
feat(compatability): Check Python Runtime (#185)
1 parent ff6aa15 commit d7c8d37

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

src/dynamodb_encryption_sdk/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""DynamoDB Encryption Client."""
14+
from dynamodb_encryption_sdk.compatability import _warn_deprecated_python
1415
from dynamodb_encryption_sdk.encrypted.client import EncryptedClient
1516
from dynamodb_encryption_sdk.encrypted.item import (
1617
decrypt_dynamodb_item,
@@ -22,6 +23,8 @@
2223
from dynamodb_encryption_sdk.encrypted.table import EncryptedTable
2324
from dynamodb_encryption_sdk.identifiers import __version__
2425

26+
_warn_deprecated_python()
27+
2528
__all__ = (
2629
"decrypt_dynamodb_item",
2730
"decrypt_python_item",
Lines changed: 39 additions & 0 deletions
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 the Python Version"""
14+
import sys
15+
import warnings
16+
17+
DEPRECATION_DATE_MAP = {"1.x": "2022-07-08", "2.x": "2022-07-15"}
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-dynamodb-encryption 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-dynamodb-encryption-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)

test/pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ disable =
1010
protected-access, # raised when calling _ methods
1111
redefined-outer-name, # raised when using pytest-mock
1212
unused-argument, # raised when patches and fixtures are needed but not called
13+
no-self-use, # raised on Classes in tests used for logically grouping tests
1314
# All below are disabled because we need to support Python 2
1415
useless-object-inheritance,
1516
raise-missing-from,

test/unit/test_compatability.py

Lines changed: 38 additions & 0 deletions
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 dynamodb_encryption_sdk.compatability."""
14+
import sys
15+
16+
import mock
17+
import pytest
18+
19+
from dynamodb_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)