Skip to content

Commit

Permalink
Add support for Python 3.12
Browse files Browse the repository at this point in the history
In addition to the mechanical changes needed to support a new Python
version, I also made a few additional changes to get everything passing:

* Removed testing cdkv1.  CDK v1 is deprecated now, and while we still have
  code that will try and import cdkv1, we're no longer testing support for
  CDK v1.
* Refresh the test/dev dependencies via `pip-compile`.  New package versions
  were needed for Python 3.12 support.
* Update the pylintrc config to match the previous behavior of earlier versions
* Only use `typing_extensions` on Python 3.7, which is the only version that
  needs this.  `TypedDict` was added in 3.8, and it's the only thing
  from that package that we use.
  • Loading branch information
jamesls committed Dec 15, 2023
1 parent 670130e commit f37256d
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 115 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.8, 3.9, '3.10', 3.11]
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand Down Expand Up @@ -53,8 +53,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10', 3.11]
cdk-version: [cdk, cdkv2]
python-version: [3.7, 3.8, 3.9, '3.10', 3.11, 3.12]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand All @@ -68,8 +67,7 @@ jobs:
run: npm install -g aws-cdk
- name: Install dependencies
run: |
pip install -r requirements-dev.txt
pip install -e .[${{ matrix.cdk-version }}]
pip install -r requirements-test.txt --upgrade --upgrade-strategy eager -e .[cdkv2]
- name: Run CDK tests
run: python -m pytest tests/functional/cdk
# Chalice works on windows, but there's some differences between
Expand Down
6 changes: 4 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=W0613,I0021,I0020,C0111,R0902,R0903,W0231,W0611,R0913,W0703,I0011,R0904,R0205,R1705,R1710,C0415,R1725,W0707,R1732,W1512,C0209,W1514
disable=W0613,I0021,I0020,C0111,R0902,R0903,W0231,W0611,R0913,W0703,I0011,R0904,R0205,R1705,R1710,C0415,R1725,W0707,R1732,W1512,C0209,W1514,C0412,C0411,R1735


[REPORTS]
Expand Down Expand Up @@ -131,6 +131,8 @@ no-docstring-rgx=.*
# ones are exempt.
docstring-min-length=-1

typevar-rgx=(([a-zA-Z_][a-zA-Z0-9_]*)|(__.*__))$
typealias-rgx=(([a-zA-Z_][a-zA-Z0-9_]*)|(__.*__))$

[FORMAT]

Expand Down Expand Up @@ -320,4 +322,4 @@ known-third-party=typing

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.Exception
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ Quickstart
In this tutorial, you'll use the ``chalice`` command line utility
to create and deploy a basic REST API. This quickstart uses Python 3.7,
but AWS Chalice supports all versions of python supported by AWS Lambda,
which includes python3.6, python3.7, python3.8, python3.9, python3.10, python3.11.
which includes Python 3.7 through python 3.12.

You can find the latest versions of python on the
`Python download page <https://www.python.org/downloads/>`_.

Expand Down
5 changes: 4 additions & 1 deletion chalice/awsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
from botocore.vendored.requests.exceptions import (
ReadTimeout as RequestsReadTimeout,
)
from typing_extensions import TypedDict
try:
from typing import TypedDict
except ImportError:
from typing_extensions import TypedDict

from chalice.constants import DEFAULT_STAGE_NAME
from chalice.constants import MAX_LAMBDA_DEPLOYMENT_SIZE
Expand Down
6 changes: 3 additions & 3 deletions chalice/cdk/construct.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
import uuid
from typing import List, Dict, Optional, Any
from typing import List, Dict, Optional, Any # noqa

from aws_cdk import (
aws_s3_assets as assets,
Expand All @@ -12,9 +12,9 @@

try:
from aws_cdk.core import Construct
from aws_cdk import core as cdk
from aws_cdk import core as cdk # noqa
except ImportError:
import aws_cdk as cdk
import aws_cdk as cdk # noqa
from constructs import Construct

from chalice import api
Expand Down
4 changes: 2 additions & 2 deletions chalice/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ def lambda_python_version(self) -> str:
# 3.11 and higher will use 3.11
elif (major, minor) <= (3, 6):
return 'python3.6'
elif (major, minor) <= (3, 10):
elif (major, minor) <= (3, 11):
return 'python%s.%s' % (major, minor)
return 'python3.11'
return 'python3.12'

@property
def log_retention_in_days(self) -> int:
Expand Down
7 changes: 6 additions & 1 deletion chalice/deploy/executor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import pprint
from dataclasses import asdict
from dataclasses import asdict, is_dataclass

import jmespath
from typing import Dict, List, Any # noqa
Expand Down Expand Up @@ -249,6 +249,11 @@ def _default_handler(self, instruction, spillover_values):
# type: (models.Instruction, Dict[str, Any]) -> None
instruction_name = self._upper_snake_case(
instruction.__class__.__name__)
# Need this to make typing happy . We're certain that we're always
# dealing with a dataclass, but the base type `Instruction` has
# no dataclass pieces. There's probably a better way to represent
# this type hierarchy.
assert is_dataclass(instruction) and not isinstance(instruction, type)
for key, value in asdict(instruction).items():
if isinstance(value, dict):
value = self._format_dict(value, spillover_values)
Expand Down
1 change: 1 addition & 0 deletions chalice/deploy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class BuiltinFunction(Instruction):
output_var: str


@dataclass
class Model(object):
def dependencies(self) -> List[Model]:
return []
Expand Down
2 changes: 2 additions & 0 deletions chalice/deploy/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class BaseLambdaDeploymentPackager(object):
'python3.9': 'cp39',
'python3.10': 'cp310',
'python3.11': 'cp311',
'python3.12': 'cp312',
}

def __init__(
Expand Down Expand Up @@ -501,6 +502,7 @@ class DependencyBuilder(object):
'cp38': (2, 26),
'cp310': (2, 26),
'cp311': (2, 26),
'cp312': (2, 26),
}
# Fallback version if we're on an unknown python version
# not in _RUNTIME_GLIBC.
Expand Down
3 changes: 2 additions & 1 deletion chalice/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

import yaml
from yaml.scanner import ScannerError
from yaml.nodes import Node, ScalarNode, SequenceNode, MappingNode
from yaml.nodes import Node # noqa
from yaml.nodes import ScalarNode, SequenceNode, MappingNode

from chalice.deploy.swagger import (
CFNSwaggerGenerator, TerraformSwaggerGenerator)
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ flake8
Sphinx==4.3.2
docutils
mypy
typing-extensions
wheel
pygments
types-six
Expand Down
109 changes: 51 additions & 58 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,31 @@
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile --output-file=requirements-dev.txt --resolver=backtracking requirements-dev.in
# pip-compile --output-file=requirements-dev.txt requirements-dev.in
#
alabaster==0.7.12
alabaster==0.7.13
# via sphinx
astroid==2.12.5
astroid==2.15.8
# via pylint
attrs==21.4.0
# via
# hypothesis
# pytest
babel==2.10.3
attrs==23.1.0
# via hypothesis
babel==2.14.0
# via sphinx
boto3==1.24.62
boto3==1.34.1
# via -r requirements-test.in
botocore==1.27.62
botocore==1.34.1
# via
# boto3
# s3transfer
certifi==2022.6.15
certifi==2023.11.17
# via requests
charset-normalizer==2.1.1
charset-normalizer==3.3.2
# via requests
coverage[toml]==6.4.4
coverage[toml]==7.3.3
# via
# -r requirements-test.in
# pytest-cov
dill==0.3.5.1
dill==0.3.7
# via pylint
doc8==0.11.2
# via -r requirements-dev.in
Expand All @@ -38,84 +36,80 @@ docutils==0.17.1
# doc8
# restructuredtext-lint
# sphinx
exceptiongroup==1.0.0rc9
# via hypothesis
flake8==5.0.4
exceptiongroup==1.2.0
# via
# hypothesis
# pytest
flake8==6.1.0
# via -r requirements-dev.in
hypothesis==6.54.4
hypothesis==6.92.0
# via -r requirements-test.in
idna==3.3
idna==3.6
# via requests
imagesize==1.4.1
# via sphinx
iniconfig==1.1.1
iniconfig==2.0.0
# via pytest
isort==5.10.1
isort==5.13.2
# via pylint
jinja2==3.1.2
# via sphinx
jmespath==1.0.1
# via
# boto3
# botocore
lazy-object-proxy==1.7.1
lazy-object-proxy==1.10.0
# via astroid
markupsafe==2.1.1
markupsafe==2.1.3
# via jinja2
mccabe==0.7.0
# via
# flake8
# pylint
mock==4.0.3
# via -r requirements-test.in
mypy==1.0.0
mypy==1.7.1
# via -r requirements-dev.in
mypy-extensions==0.4.3
mypy-extensions==1.0.0
# via mypy
packaging==21.3
packaging==23.2
# via
# pytest
# sphinx
pbr==5.10.0
pbr==6.0.0
# via stevedore
platformdirs==2.5.2
platformdirs==4.1.0
# via pylint
pluggy==1.0.0
pluggy==1.3.0
# via pytest
py==1.11.0
# via pytest
pycodestyle==2.9.1
pycodestyle==2.11.1
# via flake8
pydocstyle==6.1.1
pydocstyle==6.3.0
# via -r requirements-dev.in
pyflakes==2.5.0
pyflakes==3.1.0
# via flake8
pygments==2.13.0
pygments==2.17.2
# via
# -r requirements-dev.in
# doc8
# sphinx
pylint==2.15.0
pylint==2.17.7
# via -r requirements-dev.in
pyparsing==3.0.9
# via packaging
pytest==7.1.2
pytest==7.4.3
# via
# -r requirements-test.in
# pytest-cov
pytest-cov==3.0.0
pytest-cov==4.1.0
# via -r requirements-test.in
python-dateutil==2.8.2
# via botocore
pytz==2022.2.1
pytz==2023.3.post1
# via babel
requests==2.28.1
requests==2.31.0
# via
# -r requirements-test.in
# sphinx
restructuredtext-lint==1.4.0
# via doc8
s3transfer==0.6.0
s3transfer==0.9.0
# via boto3
six==1.16.0
# via python-dateutil
Expand All @@ -127,49 +121,48 @@ sortedcontainers==2.4.0
# via hypothesis
sphinx==4.3.2
# via -r requirements-dev.in
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-applehelp==1.0.4
# via sphinx
sphinxcontrib-devhelp==1.0.2
# via sphinx
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-htmlhelp==2.0.1
# via sphinx
sphinxcontrib-jsmath==1.0.1
# via sphinx
sphinxcontrib-qthelp==1.0.3
# via sphinx
sphinxcontrib-serializinghtml==1.1.5
# via sphinx
stevedore==3.5.0
stevedore==5.1.0
# via doc8
tomli==2.0.1
# via
# coverage
# mypy
# pylint
# pytest
tomlkit==0.11.4
tomlkit==0.12.3
# via pylint
types-python-dateutil==2.8.19.6
types-python-dateutil==2.8.19.14
# via -r requirements-dev.in
types-pyyaml==6.0.12.6
types-pyyaml==6.0.12.12
# via -r requirements-dev.in
types-six==1.16.21.4
types-six==1.16.21.9
# via -r requirements-dev.in
typing-extensions==4.4.0
typing-extensions==4.9.0
# via
# -r requirements-dev.in
# astroid
# mypy
# pylint
urllib3==1.26.12
urllib3==1.26.18
# via
# botocore
# requests
websocket-client==1.4.0
websocket-client==1.7.0
# via -r requirements-test.in
wheel==0.37.1
wheel==0.42.0
# via -r requirements-dev.in
wrapt==1.14.1
wrapt==1.16.0
# via astroid

# The following packages are considered to be unsafe in a requirements file:
Expand Down
Loading

0 comments on commit f37256d

Please sign in to comment.