Skip to content

Commit 5d90a9a

Browse files
authored
Support Python 3.12 (#392)
* Update tooling and documentation to include Python3.12. * Replace deprecated assertEquals in tests. * Remove httpretty which does not support Python3.12. * Fix new flake8 errors. * Add snapshots for python3.12.
1 parent cce5104 commit 5d90a9a

16 files changed

+3309
-69
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
strategy:
4242
max-parallel: 4
4343
matrix:
44-
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
44+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
4545

4646
steps:
4747
- name: Checkout
@@ -68,7 +68,7 @@ jobs:
6868
runs-on: ubuntu-latest
6969
strategy:
7070
matrix:
71-
runtime-param: ['3.7', '3.8', '3.9', '3.10', '3.11']
71+
runtime-param: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
7272
steps:
7373
- name: Checkout
7474
uses: actions/checkout@v3

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 (3.7, 3.8, 3.9, 3.10, and 3.11) enables [enhanced Lambda metrics](https://docs.datadoghq.com/serverless/enhanced_lambda_metrics), [distributed tracing](https://docs.datadoghq.com/serverless/distributed_tracing), and [custom metric submission](https://docs.datadoghq.com/serverless/custom_metrics) from AWS Lambda functions.
9+
Datadog Lambda Library for Python (3.7, 3.8, 3.9, 3.10, 3.11, and 3.12) enables [enhanced Lambda metrics](https://docs.datadoghq.com/serverless/enhanced_lambda_metrics), [distributed tracing](https://docs.datadoghq.com/serverless/distributed_tracing), and [custom metric submission](https://docs.datadoghq.com/serverless/custom_metrics) from AWS Lambda functions.
1010

1111
## Installation
1212

datadog_lambda/tracing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,8 @@ def inject_correlation_ids():
569569
# Override the log format of the AWS provided LambdaLoggerHandler
570570
root_logger = logging.getLogger()
571571
for handler in root_logger.handlers:
572-
if (
573-
handler.__class__.__name__ == "LambdaLoggerHandler"
574-
and type(handler.formatter) == logging.Formatter
572+
if handler.__class__.__name__ == "LambdaLoggerHandler" and isinstance(
573+
handler.formatter, logging.Formatter
575574
):
576575
handler.setFormatter(
577576
logging.Formatter(

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ classifiers = [
2121
"Programming Language :: Python :: 3.9",
2222
"Programming Language :: Python :: 3.10",
2323
"Programming Language :: Python :: 3.11",
24+
"Programming Language :: Python :: 3.12",
2425
]
2526

2627
[tool.poetry.dependencies]
@@ -37,8 +38,7 @@ boto3 = { version = "^1.28.0", optional = true }
3738
typing_extensions = {version = "^4.0", python = "<3.8"}
3839
requests = { version ="^2.22.0", optional = true }
3940
nose2 = { version= "^0.9.1", optional = true }
40-
flake8 = { version = "^3.7.9", optional = true }
41-
httpretty = {version = "^0.9.7", optional = true }
41+
flake8 = { version = "^5.0.4", optional = true }
4242

4343

4444
[tool.poetry.extras]
@@ -47,7 +47,6 @@ dev = [
4747
"requests",
4848
"nose2",
4949
"flake8",
50-
"httpretty",
5150
]
5251

5352
[build-system]

scripts/add_new_region.sh

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

1313
OLD_REGION='us-east-1'
1414

15-
LAYER_NAMES=("Datadog-Python37" "Datadog-Python38" "Datadog-Python38-ARM" "Datadog-Python39" "Datadog-Python39-ARM" "Datadog-Python310" "Datadog-Python310-ARM" "Datadog-Python311" "Datadog-Python311-ARM")
16-
PYTHON_VERSIONS_FOR_AWS_CLI=("python3.7" "python3.8" "python3.8" "python3.9" "python3.9" "python3.10" "python3.10" "python3.11" "python3.11")
15+
LAYER_NAMES=(
16+
"Datadog-Python37"
17+
"Datadog-Python38"
18+
"Datadog-Python38-ARM"
19+
"Datadog-Python39"
20+
"Datadog-Python39-ARM"
21+
"Datadog-Python310"
22+
"Datadog-Python310-ARM"
23+
"Datadog-Python311"
24+
"Datadog-Python311-ARM"
25+
"Datadog-Python312"
26+
"Datadog-Python312-ARM"
27+
)
28+
PYTHON_VERSIONS_FOR_AWS_CLI=(
29+
"python3.7"
30+
"python3.8"
31+
"python3.8"
32+
"python3.9"
33+
"python3.9"
34+
"python3.10"
35+
"python3.10"
36+
"python3.11"
37+
"python3.11"
38+
"python3.12"
39+
"python3.12"
40+
)
1741
NEW_REGION=$1
1842

1943
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=("3.7" "3.8" "3.9" "3.10" "3.11")
17+
AVAILABLE_PYTHON_VERSIONS=("3.7" "3.8" "3.9" "3.10" "3.11" "3.12")
1818

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

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 24 \* 1024)
1414

1515
LAYER_FILES_PREFIX="datadog_lambda_py"
1616
LAYER_DIR=".layers"
17-
VERSIONS=("3.7" "3.8" "3.9" "3.10" "3.11")
17+
VERSIONS=("3.7" "3.8" "3.9" "3.10" "3.11" "3.12")
1818

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

scripts/list_layers.sh

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

1111
set -e
1212

13-
LAYER_NAMES=("Datadog-Python37" "Datadog-Python38" "Datadog-Python38-ARM" "Datadog-Python39" "Datadog-Python39-ARM" "Datadog-Python310" "Datadog-Python310-ARM" "Datadog-Python311" "Datadog-Python311-ARM")
13+
LAYER_NAMES=(
14+
"Datadog-Python37"
15+
"Datadog-Python38"
16+
"Datadog-Python38-ARM"
17+
"Datadog-Python39"
18+
"Datadog-Python39-ARM"
19+
"Datadog-Python310"
20+
"Datadog-Python310-ARM"
21+
"Datadog-Python311"
22+
"Datadog-Python311-ARM"
23+
"Datadog-Python312"
24+
"Datadog-Python312-ARM"
25+
)
1426
AVAILABLE_REGIONS=$(aws ec2 describe-regions | jq -r '.[] | .[] | .RegionName')
1527
LAYERS_MISSING_REGIONS=()
1628

scripts/publish_layers.sh

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,45 @@ set -e
1313
# Makes sure any subprocesses will be terminated with this process
1414
trap "pkill -P $$; exit 1;" INT
1515

16-
PYTHON_VERSIONS_FOR_AWS_CLI=("python3.7" "python3.8" "python3.8" "python3.9" "python3.9" "python3.10" "python3.10" "python3.11" "python3.11")
17-
LAYER_PATHS=(".layers/datadog_lambda_py-amd64-3.7.zip" ".layers/datadog_lambda_py-amd64-3.8.zip" ".layers/datadog_lambda_py-arm64-3.8.zip" ".layers/datadog_lambda_py-amd64-3.9.zip" ".layers/datadog_lambda_py-arm64-3.9.zip" ".layers/datadog_lambda_py-amd64-3.10.zip" ".layers/datadog_lambda_py-arm64-3.10.zip" ".layers/datadog_lambda_py-amd64-3.11.zip" ".layers/datadog_lambda_py-arm64-3.11.zip")
18-
AVAILABLE_LAYERS=("Datadog-Python37" "Datadog-Python38" "Datadog-Python38-ARM" "Datadog-Python39" "Datadog-Python39-ARM" "Datadog-Python310" "Datadog-Python310-ARM" "Datadog-Python311" "Datadog-Python311-ARM")
19-
ARCHS=("amd64" "amd64" "amd64""amd64" "amd64" "arm64" "amd64" "arm64" "amd64" "arm64")
16+
PYTHON_VERSIONS_FOR_AWS_CLI=(
17+
"python3.7"
18+
"python3.8"
19+
"python3.8"
20+
"python3.9"
21+
"python3.9"
22+
"python3.10"
23+
"python3.10"
24+
"python3.11"
25+
"python3.11"
26+
"python3.12"
27+
"python3.12"
28+
)
29+
LAYER_PATHS=(
30+
".layers/datadog_lambda_py-amd64-3.7.zip"
31+
".layers/datadog_lambda_py-amd64-3.8.zip"
32+
".layers/datadog_lambda_py-arm64-3.8.zip"
33+
".layers/datadog_lambda_py-amd64-3.9.zip"
34+
".layers/datadog_lambda_py-arm64-3.9.zip"
35+
".layers/datadog_lambda_py-amd64-3.10.zip"
36+
".layers/datadog_lambda_py-arm64-3.10.zip"
37+
".layers/datadog_lambda_py-amd64-3.11.zip"
38+
".layers/datadog_lambda_py-arm64-3.11.zip"
39+
".layers/datadog_lambda_py-amd64-3.12.zip"
40+
".layers/datadog_lambda_py-arm64-3.12.zip"
41+
)
42+
AVAILABLE_LAYERS=(
43+
"Datadog-Python37"
44+
"Datadog-Python38"
45+
"Datadog-Python38-ARM"
46+
"Datadog-Python39"
47+
"Datadog-Python39-ARM"
48+
"Datadog-Python310"
49+
"Datadog-Python310-ARM"
50+
"Datadog-Python311"
51+
"Datadog-Python311-ARM"
52+
"Datadog-Python312"
53+
"Datadog-Python312-ARM"
54+
)
2055
AVAILABLE_REGIONS=$(aws ec2 describe-regions | jq -r '.[] | .[] | .RegionName')
2156

2257
BATCH_SIZE=60

scripts/run_integration_tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ set -e
1111
# These values need to be in sync with serverless.yml, where there needs to be a function
1212
# defined for every handler_runtime combination
1313
LAMBDA_HANDLERS=("async-metrics" "sync-metrics")
14-
RUNTIMES=("python37" "python38" "python39" "python310" "python311")
1514

1615
LOGS_WAIT_SECONDS=20
1716

@@ -33,8 +32,9 @@ python38=("python3.8" "3.8" $(xxd -l 4 -c 4 -p < /dev/random))
3332
python39=("python3.9" "3.9" $(xxd -l 4 -c 4 -p < /dev/random))
3433
python310=("python3.10" "3.10" $(xxd -l 4 -c 4 -p < /dev/random))
3534
python311=("python3.11" "3.11" $(xxd -l 4 -c 4 -p < /dev/random))
35+
python312=("python3.12" "3.12" $(xxd -l 4 -c 4 -p < /dev/random))
3636

37-
PARAMETERS_SETS=("python37" "python38" "python39" "python310" "python311")
37+
PARAMETERS_SETS=("python37" "python38" "python39" "python310" "python311" "python312")
3838

3939
if [ -z "$RUNTIME_PARAM" ]; then
4040
echo "Python version not specified, running for all python versions."

scripts/run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Run unit tests in Docker
99
set -e
1010

11-
PYTHON_VERSIONS=("3.7" "3.8" "3.9" "3.10" "3.11")
11+
PYTHON_VERSIONS=("3.7" "3.8" "3.9" "3.10" "3.11" "3.12")
1212

1313
for python_version in "${PYTHON_VERSIONS[@]}"
1414
do

scripts/sign_layers.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ LAYER_FILES=(
1818
"datadog_lambda_py-arm64-3.10.zip"
1919
"datadog_lambda_py-amd64-3.11.zip"
2020
"datadog_lambda_py-arm64-3.11.zip"
21+
"datadog_lambda_py-amd64-3.12.zip"
22+
"datadog_lambda_py-arm64-3.12.zip"
2123
)
2224
SIGNING_PROFILE_NAME="DatadogLambdaSigningProfile"
2325

0 commit comments

Comments
 (0)