Skip to content

Commit 87faedd

Browse files
authored
Drop support for python 2.7 (#181)
* remove support in tests, files, and documentation * remove conditional imports * remove trailing spaces * remove try/catch for imports * try to fix lint * add a single empty line * make local a variable and remove docstrings for python2 * fix unit tests
1 parent 6d589dd commit 87faedd

26 files changed

+73
-188
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
strategy:
3838
max-parallel: 4
3939
matrix:
40-
python-version: [2.7, 3.6, 3.7, 3.8, 3.9]
40+
python-version: [3.6, 3.7, 3.8, 3.9]
4141

4242
steps:
4343
- name: Checkout
@@ -64,7 +64,7 @@ jobs:
6464
runs-on: ubuntu-latest
6565
strategy:
6666
matrix:
67-
runtime-param: [2.7, 3.6, 3.7, 3.8, 3.9]
67+
runtime-param: [3.6, 3.7, 3.8, 3.9]
6868
steps:
6969
- name: Checkout
7070
uses: actions/checkout@v2

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
We love pull requests. For new features, consider opening an issue to discuss the idea first. When you're ready to open a pull request, here's a quick guide.
44

55
1. Fork, clone and branch off `main`:
6-
```bash
7-
git clone git@github.com:<your-username>/datadog-lambda-python.git
8-
git checkout -b <my-branch>
9-
```
10-
1. Make your changes. Ensure your code is compatible with both Python 2.7 and 3.X.
6+
```bash
7+
git clone git@github.com:<your-username>/datadog-lambda-python.git
8+
git checkout -b <my-branch>
9+
```
10+
1. Make your changes. Ensure your code is compatible with Python 3.X.
1111
1. Test your Lambda function against the locally modified version of Datadog Lambda library.
1212

1313
- The easiest approach is to create a soft link of the `datadog_lambda` folder in your project's root. Note, this only overrides the `datadog_lambda` module, and you still need to install the `datadog_lambda` package or the Lambda layer to have the required dependencies.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Slack](https://chat.datadoghq.com/badge.svg?bg=632CA6)](https://chat.datadoghq.com/)
77
[![License](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/DataDog/datadog-lambda-python/blob/main/LICENSE)
88

9-
Datadog Lambda Library for Python (2.7, 3.6, 3.7, 3.8, and 3.9) enables enhanced Lambda metrics, distributed tracing, and custom metric submission from AWS Lambda functions.
9+
Datadog Lambda Library for Python (3.6, 3.7, 3.8, and 3.9) enables enhanced Lambda metrics, distributed tracing, and custom metric submission from AWS Lambda functions.
1010

1111
**IMPORTANT NOTE:** AWS Lambda is expected to receive a [breaking change](https://aws.amazon.com/blogs/compute/upcoming-changes-to-the-python-sdk-in-aws-lambda/) on **March 31, 2021**. If you are using Datadog Python Lambda layer version 7 or below, please upgrade to the latest.
1212

datadog_lambda/patch.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,11 @@
1717
get_dd_trace_context,
1818
dd_tracing_enabled,
1919
)
20+
from collections.abc import MutableMapping
2021

2122
logger = logging.getLogger(__name__)
2223

23-
if sys.version_info >= (3, 0, 0):
24-
httplib_module = "http.client"
25-
from collections.abc import MutableMapping
26-
else:
27-
httplib_module = "httplib"
28-
from collections import MutableMapping
29-
30-
_httplib_patched = False
24+
_http_patched = False
3125
_requests_patched = False
3226
_integration_tests_patched = False
3327

@@ -41,7 +35,7 @@ def patch_all():
4135
if dd_tracing_enabled:
4236
patch_all_dd()
4337
else:
44-
_patch_httplib()
38+
_patch_http()
4539
_ensure_patch_requests()
4640

4741

@@ -56,17 +50,17 @@ def _patch_for_integration_tests():
5650
_integration_tests_patched = True
5751

5852

59-
def _patch_httplib():
53+
def _patch_http():
6054
"""
61-
Patch the Python built-in `httplib` (Python 2) or
62-
`http.client` (Python 3) module.
55+
Patch `http.client` (Python 3) module.
6356
"""
64-
global _httplib_patched
65-
if not _httplib_patched:
66-
_httplib_patched = True
67-
wrap(httplib_module, "HTTPConnection.request", _wrap_httplib_request)
57+
global _http_patched
58+
http_module = "http.client"
59+
if not _http_patched:
60+
_http_patched = True
61+
wrap(http_module, "HTTPConnection.request", _wrap_http_request)
6862

69-
logger.debug("Patched %s", httplib_module)
63+
logger.debug("Patched %s", http_module)
7064

7165

7266
def _ensure_patch_requests():
@@ -113,9 +107,9 @@ def _wrap_requests_request(func, instance, args, kwargs):
113107
return func(*args, **kwargs)
114108

115109

116-
def _wrap_httplib_request(func, instance, args, kwargs):
110+
def _wrap_http_request(func, instance, args, kwargs):
117111
"""
118-
Wrap `httplib` (python2) or `http.client` (python3) to inject
112+
Wrap `http.client` (python3) to inject
119113
the Datadog trace headers into the outgoing requests.
120114
"""
121115
context = get_dd_trace_context()

datadog_lambda/tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def _format_dd_lambda_layer_tag():
1010
"""
11-
Formats the dd_lambda_layer tag, e.g., 'dd_lambda_layer:datadog-python27_1'
11+
Formats the dd_lambda_layer tag, e.g., 'dd_lambda_layer:datadog-python39_1'
1212
"""
1313
runtime = "python{}{}".format(sys.version_info[0], sys.version_info[1])
1414
return "dd_lambda_layer:datadog-{}_{}".format(runtime, __version__)

scripts/add_new_region.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ set -e
1212

1313
OLD_REGION='us-east-1'
1414

15-
PYTHON_VERSIONS_FOR_AWS_CLI=("python2.7" "python3.6" "python3.7" "python3.8" "python3.9")
16-
LAYER_NAMES=("Datadog-Python27" "Datadog-Python36" "Datadog-Python37" "Datadog-Python38" "Datadog-Python39")
15+
PYTHON_VERSIONS_FOR_AWS_CLI=("python3.6" "python3.7" "python3.8" "python3.9")
16+
LAYER_NAMES=("Datadog-Python36" "Datadog-Python37" "Datadog-Python38" "Datadog-Python39")
1717
NEW_REGION=$1
1818

1919
publish_layer() {

scripts/build_layers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set -e
1414

1515
LAYER_DIR=".layers"
1616
LAYER_FILES_PREFIX="datadog_lambda_py"
17-
AVAILABLE_PYTHON_VERSIONS=("2.7" "3.6" "3.7" "3.8" "3.9")
17+
AVAILABLE_PYTHON_VERSIONS=("3.6" "3.7" "3.8" "3.9")
1818

1919
# Determine which Python versions to build layers for
2020
if [ -z "$PYTHON_VERSION" ]; then

scripts/check_format.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
set -e
33

44
PYTHON_VERSION=$(python -c 'import sys; print(sys.version_info.major)')
5-
if [ "$PYTHON_VERSION" = "2" ]; then
6-
echo "Skipping formatting, black not compatible with python 2"
7-
exit 0
8-
fi
95
pip install -Iv black==21.5b2
106

117
python -m black --check datadog_lambda/ --diff

scripts/check_layer_size.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ MAX_LAYER_UNCOMPRESSED_SIZE_KB=$(expr 16 \* 1024)
1414

1515
LAYER_FILES_PREFIX="datadog_lambda_py"
1616
LAYER_DIR=".layers"
17-
VERSIONS=("2.7" "3.6" "3.7" "3.8" "3.9")
17+
VERSIONS=("3.6" "3.7" "3.8" "3.9")
1818

1919
for version in "${VERSIONS[@]}"
2020
do

scripts/list_layers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
set -e
1212

13-
LAYER_NAMES=("Datadog-Python27" "Datadog-Python36" "Datadog-Python37" "Datadog-Python38" "Datadog-Python38-ARM" "Datadog-Python39" "Datadog-Python39-ARM")
13+
LAYER_NAMES=("Datadog-Python36" "Datadog-Python37" "Datadog-Python38" "Datadog-Python38-ARM" "Datadog-Python39" "Datadog-Python39-ARM")
1414
AVAILABLE_REGIONS=$(aws ec2 describe-regions | jq -r '.[] | .[] | .RegionName')
1515
LAYERS_MISSING_REGIONS=()
1616

0 commit comments

Comments
 (0)