Skip to content

feat(compatability): Check Python Runtime #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/dynamodb_encryption_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
39 changes: 39 additions & 0 deletions src/dynamodb_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 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)
1 change: 1 addition & 0 deletions test/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 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()