Skip to content

Bring lambda Python in line with project conventions; build lambdas in CI#2152

Merged
mattgodbolt merged 2 commits into
mainfrom
lambda-housekeeping
Jun 4, 2026
Merged

Bring lambda Python in line with project conventions; build lambdas in CI#2152
mattgodbolt merged 2 commits into
mainfrom
lambda-housekeeping

Conversation

@mattgodbolt
Copy link
Copy Markdown
Member

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 utcnow fix; 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:

  • Add FA, UP, PLC, BLE001 to the ruff select, and require from __future__ import annotations via isort required-imports.
  • Apply the fixes: future-annotations imports across all files, PEP 585/604 typing (dict, X | None), and datetime.UTC.
  • Replace deprecated datetime.utcnow() with timezone-aware datetime.now(datetime.UTC) in stats.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.yaml ran make test and make static-checks but 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-checks clean
  • uv run pytest lambda/ -- 25 passed, 1 skipped
  • both zips build via the exact CI command

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings June 4, 2026 01:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 enforcing from __future__ import annotations via isort required imports.
  • Apply automated modernization fixes across Lambda sources/tests (PEP 585/604 typing, future annotations import, and datetime.UTC usage), including replacing deprecated utcnow() with timezone-aware now(datetime.UTC) in stats.py.
  • Extend the Python CI workflow to build both lambda-package and events-lambda-package artifacts (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>
@mattgodbolt mattgodbolt merged commit 71748d7 into main Jun 4, 2026
1 check passed
@mattgodbolt mattgodbolt deleted the lambda-housekeeping branch June 4, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants