Bring lambda Python in line with project conventions; build lambdas in CI#2152
Merged
Conversation
…n CI Align lambda/ ruff config with the root project: add FA, UP, PLC and BLE001, and require `from __future__ import annotations`. Apply the resulting fixes across lambda/ -- future-annotations imports, PEP 585/604 typing (dict/`X | None`), and datetime.UTC. Separately replace the deprecated datetime.utcnow() with timezone-aware now() in stats. Add a CI step that builds both lambda zips (build only, no upload or terraform) so dependency-resolution or packaging breakage surfaces on the PR rather than at deploy time. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR performs low-risk housekeeping on the lambda/ Python code to match the repository’s Python conventions (ruff/isort rules, modern typing, and timezone-aware datetimes), and updates CI to build both Lambda ZIP artifacts to catch packaging/dependency issues earlier.
Changes:
- Align
lambda/linting with the root project by expanding ruff rule selection and enforcingfrom __future__ import annotationsvia isort required imports. - Apply automated modernization fixes across Lambda sources/tests (PEP 585/604 typing, future annotations import, and
datetime.UTCusage), including replacing deprecatedutcnow()with timezone-awarenow(datetime.UTC)instats.py. - Extend the Python CI workflow to build both
lambda-packageandevents-lambda-packageartifacts (build-only, no deploy).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
lambda/status.py |
Adds future-annotations import and switches timestamp generation to datetime.now(UTC) for UTC-aware timestamps. |
lambda/status_test.py |
Adds future-annotations import to comply with enforced isort required imports. |
lambda/stats.py |
Modernizes typing annotations and replaces deprecated utcnow() with now(datetime.UTC) (UTC-aware). |
lambda/stats_test.py |
Updates typing usage and adds future-annotations import to align with new lint rules. |
lambda/pyproject.toml |
Expands ruff rule selection and enforces future-annotations via ruff.lint.isort.required-imports. |
lambda/get_remote_execution_archs.py |
Adds future-annotations import to satisfy new lint configuration. |
lambda/get_deployed_exe_version.py |
Adds future-annotations import and modernizes Dict typing to dict. |
lambda/cloudwatch_to_discord.py |
Adds future-annotations import to satisfy new lint configuration. |
lambda/cloudwatch_to_discord_test.py |
Adds future-annotations import to satisfy new lint configuration. |
lambda/alert_on_elb_instance.py |
Adds future-annotations import to satisfy new lint configuration. |
lambda/alert_on_elb_instance_test.py |
Adds future-annotations import to satisfy new lint configuration. |
.github/workflows/python-tests.yaml |
Adds a CI step to build both Lambda ZIP packages to catch packaging issues in PRs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The `from __future__ import annotations` convention isn't policed anywhere: ruff's FA rule is a no-op at our py312 target and nothing requires the import, so the earlier blanket enforcement (required-imports plus the imports it added) bought nothing on 3.12 where the modern typing works natively. Remove the rule and the added imports, and drop the matching CLAUDE.md line. The typing modernization, datetime fixes and CI build step stay. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These lambdas don't get much attention, so this is some low-risk housekeeping to slow the bitrot. No behavior change to deployed functions beyond the
utcnowfix; nothing here deploys.Python conventions
The
lambda/subdir had its own ruff config (E,W,F,B,I) that was laxer than the root project, which is why it drifted. This aligns it with root:FA,UP,PLC,BLE001to the ruff select, and requirefrom __future__ import annotationsvia isortrequired-imports.dict,X | None), anddatetime.UTC.datetime.utcnow()with timezone-awaredatetime.now(datetime.UTC)instats.py(output for the strftime keys is unchanged; tests still pass).Python runtime is already 3.12 across root and lambda, matching a current supported Lambda runtime, so no version change needed.
CI bitrot guard
python-tests.yamlranmake testandmake static-checksbut never built the lambda packages -- so dependency-resolution or packaging breakage only showed up at deploy time. Added a build-only step (make lambda-package events-lambda-package); it does not upload to S3 or run terraform.Validation
make static-checkscleanuv run pytest lambda/-- 25 passed, 1 skipped🤖 Generated with Claude Code