Skip to content

[v2] Modernize repo with latest python standards #2140

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

Open
wants to merge 8 commits into
base: v2
Choose a base branch
from
Open
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
39 changes: 12 additions & 27 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ on:
push:
branches:
- master
- v2
- "v2-*"
- "feature/**"
pull_request:
branches:
- master
- v2
- "feature/**"
jobs:
prcheck:
Expand All @@ -17,39 +20,21 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
python-version: [3.12]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, last comment, I know we say we support 3.12+ and Lambda doesn't currently support 3.13. Would it hurt to test 3.13 now so things are ready to go as soon as Lambda releases?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, they already released 3.13. Would that be worth adding?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll sync with @jonathan343 on this, but I had assumed we'd need #2137 to land before we can test on 3.13 (and pass). If we're still targeting the master branch for that PR, which I think makes sense, once it's merged we can rebase it into v2.

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
name: Set up Python ${{ matrix.python-version }}
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
make install-dev-deps
- name: Run PRCheck
run: make prcheck
cdktests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- name: Install a specific version of uv
uses: astral-sh/setup-uv@v3
with:
node-version: '14'
- uses: actions/setup-python@v2
name: Set up Python ${{ matrix.python-version }}
with:
python-version: ${{ matrix.python-version }}
- name: Install CDK
run: npm install -g aws-cdk
version: "0.4.20"
- name: Install dependencies
run: |
pip install -r requirements-test.txt --upgrade --upgrade-strategy eager -e .[cdkv2]
- name: Run CDK tests
run: python -m pytest tests/functional/cdk
run: uv sync --all-extras --dev
- name: Run PRCheck
run: uv run make prcheck
# Chalice works on windows, but there's some differences between
# the GitHub actions windows environment and our windows dev
# laptops that are causing certain tests to fail. Once these
Expand Down
2 changes: 0 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
init-hook="import sys, os; sys.path.append(os.path.join('tests', 'plugins'))"

# Add files or directories to the blacklist. They should be base names, not
# paths.
Expand All @@ -16,7 +15,6 @@ persistent=yes

# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=codelinter,testlinter

# Use multiple processes to speed up Pylint.
jobs=1
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7
3.12
15 changes: 3 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@
TESTS=tests/unit tests/functional tests/integration

check:
###### FLAKE8 #####
# No unused imports, no undefined vars,
flake8 --ignore=E731,W503,W504 --exclude chalice/__init__.py,chalice/compat.py,chalice/vendored/botocore/regions.py --max-complexity 10 chalice/
flake8 --ignore=E731,W503,W504,F401 --max-complexity 10 chalice/compat.py
flake8 tests/unit/ tests/functional/ tests/integration tests/aws
ruff check
pylint --rcfile .pylintrc -E chalice
#
# Proper docstring conventions according to pep257
#
#
pydocstyle --add-ignore=D100,D101,D102,D103,D104,D105,D107,D204,D301 --match='(?!(test_|regions)).*\.py' chalice/

pylint:
###### PYLINT ######
pylint --rcfile .pylintrc chalice
# Run our custom linter on test code.
pylint --disable=I,E,W,R,C,F --enable C9999,C9998 tests/

test:
py.test -v $(TESTS)

Expand Down Expand Up @@ -55,7 +46,7 @@ doccheck:
# so any sphinx-build warnings will fail the build.
$(MAKE) -C docs html

prcheck: check pylint coverage doccheck typecheck
prcheck: check coverage doccheck typecheck

install-dev-deps:
pip install -r requirements-dev.txt --upgrade --upgrade-strategy eager -e .
24 changes: 24 additions & 0 deletions chalice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,27 @@
)
# We're reassigning version here to keep mypy happy.
__version__ = chalice_version
__all__ = [
"Chalice",
"Blueprint",
"ChaliceViewError",
"BadRequestError",
"UnauthorizedError",
"ForbiddenError",
"NotFoundError",
"ConflictError",
"TooManyRequestsError",
"Response",
"CORSConfig",
"CustomAuthorizer",
"CognitoUserPoolAuthorizer",
"IAMAuthorizer",
"UnprocessableEntityError",
"WebsocketDisconnectedError",
"AuthResponse",
"AuthRoute",
"Cron",
"Rate",
"ConvertToMiddleware",
"ChaliceUnhandledError",
]
5 changes: 1 addition & 4 deletions chalice/awsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
from botocore.vendored.requests.exceptions import (
ReadTimeout as RequestsReadTimeout,
)
try:
from typing import TypedDict
except ImportError:
from typing_extensions import TypedDict
from typing import TypedDict

from chalice.constants import DEFAULT_STAGE_NAME
from chalice.constants import MAX_LAMBDA_DEPLOYMENT_SIZE
Expand Down
8 changes: 0 additions & 8 deletions chalice/compat.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import socket
import six
import os

from typing import Dict, Any # noqa
from urllib.parse import urlparse, parse_qs

from six import StringIO


STRING_TYPES = six.string_types


def pip_import_string():
Expand Down
3 changes: 1 addition & 2 deletions chalice/deploy/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from chalice.constants import EXPERIMENTAL_ERROR_MSG
from chalice.constants import MIN_COMPRESSION_SIZE
from chalice.constants import MAX_COMPRESSION_SIZE
from chalice.compat import STRING_TYPES


class ExperimentalFeatureError(Exception):
Expand Down Expand Up @@ -273,7 +272,7 @@ def validate_environment_variables_type(config):
def _validate_environment_variables(environment_variables):
# type: (Dict[str, Any]) -> None
for key, value in environment_variables.items():
if not isinstance(value, STRING_TYPES):
if not isinstance(value, str):
raise ValueError("Environment variable values must be strings, "
"got 'type' %s for key '%s'" % (
type(value).__name__, key))
2 changes: 1 addition & 1 deletion chalice/invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from chalice.config import DeployedResources # noqa
from chalice.awsclient import TypedAWSClient # noqa
from chalice.utils import UI # noqa
from chalice.compat import StringIO
from io import StringIO


OptBytes = Optional[bytes]
Expand Down
9 changes: 4 additions & 5 deletions chalice/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
This is intended only for local development purposes.

"""
from __future__ import print_function
from __future__ import annotations
import re
import threading
Expand All @@ -15,9 +14,9 @@
from collections import namedtuple
import json

from six.moves.BaseHTTPServer import HTTPServer
from six.moves.BaseHTTPServer import BaseHTTPRequestHandler
from six.moves.socketserver import ThreadingMixIn
from http.server import HTTPServer
from http.server import BaseHTTPRequestHandler
from socketserver import ThreadingMixIn
from typing import (
List,
Any,
Expand All @@ -38,7 +37,7 @@
from chalice.app import BuiltinAuthConfig # noqa
from chalice.config import Config # noqa

from chalice.compat import urlparse, parse_qs
from urllib.parse import urlparse, parse_qs


MatchResult = namedtuple('MatchResult', ['route', 'captured', 'query_params'])
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/samples/todo-app/code/create-resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def create_auth_key_if_needed(stage):
try:
ssm.get_parameter(Name=AUTH_KEY_PARAM_NAME)
except ssm.exceptions.ParameterNotFound:
print(f"Generating auth key.")
print("Generating auth key.")
kms = boto3.client('kms')
random_bytes = kms.generate_random(NumberOfBytes=32)['Plaintext']
encoded_random_bytes = base64.b64encode(random_bytes).decode()
Expand Down
81 changes: 81 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[project]
name = "chalice"
version = "1.31.3"
description = "A framework for writing serverless applications"
readme = "README.rst"
authors = [
{name = "James Saryerwinnie", email = "[email protected]"},
]
license = {text = "Apache License 2.0"}
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.12",
]
keywords = ["chalice"]
requires-python = ">=3.12"
dependencies = [
"click>=7,<9.0",
"botocore>=1.14.0,<2.0.0",
"pip>=9,<24.4",
"jmespath>=0.9.3,<2.0.0",
"pyyaml>=5.3.1,<7.0.0",
"inquirer>=3.0.0,<4.0.0",
"wheel",
"setuptools",
"sphinx>=4.3.2",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project.optional-dependencies]
event-file-poller = ["watchdog==2.3.1"]
cdkv2 = ["aws-cdk-lib>2.0,<3.0"]

[project.urls]
Homepage = "https://aws.github.io/chalice/"

[tool.uv]
dev-dependencies = [
"ruff",
"pylint",
"doc8<1.0.0",
"pydocstyle",
"Sphinx>=5.0.0,<6.0.0",
"docutils",
"mypy",
"wheel",
"pygments",
"types-six",
"types-python-dateutil",
"types-PyYAML",
"pytest",
"boto3<2.0.0",
"hypothesis",
"coverage",
"websocket-client<2.0.0",
"pytest-cov",
"requests",
]

[tool.ruff]
exclude = ["chalice/vendored/*", "chalice/templates/*"]

[project.scripts]
chalice = "chalice.cli:main"

[tool.mypy]
packages = ["chalice"]

[[tool.mypy.overrides]]
module = "chalice.vendored.*"
ignore_errors = true

[[tool.mypy.overrides]]
module = "chalice.templates.*"
ignore_errors = true
13 changes: 0 additions & 13 deletions requirements-dev.in

This file was deleted.

Loading