Skip to content

More backporting pyrefly + vacuum - #203

Merged
zendern merged 5 commits into
mainfrom
more-backporting-pyrefly-vacuum
Jul 28, 2026
Merged

More backporting pyrefly + vacuum#203
zendern merged 5 commits into
mainfrom
more-backporting-pyrefly-vacuum

Conversation

@zendern

@zendern zendern commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Why is this change necessary?

pyrefly need the same setup that we have for pyright to add the configuration for firmware if its a circuit_python_driver. It also needs some ignores for vacuum in the circuit_python_driver case. We also had a test in a downstream repo that really should never be needed since we will always have an app with routes. So instead of carrying that test up here we just added an ignores.

How does this change address the issue?

Backports the changes

What side effects does this change have?

N/A

How is this change tested?

CI here and tested downstream

Summary by CodeRabbit

  • New Features

    • Added a new “driver” tag to generated OpenAPI documentation for clearer organization.
  • Bug Fixes

    • Improved generated development configuration to ensure firmware search paths are included when circuit-python driver support is enabled.
    • Expanded circuit-python driver-related request/endpoint exemptions to prevent unnecessary vacuum/validation issues for driver circuits and device-connection requests.
  • Documentation

    • Kept generated OpenAPI validation-error schema metadata application consistent while refining the OpenAPI enrichment logic formatting.

zendern added 4 commits July 26, 2026 20:49
pyrefly setup for circuit drivers and ignore for a code path that wont
happen since we would never have an app with no routes
The .camel_case_model import was placed after the
is_circuit_python_driver-gated .common/.driver_routes block, so when that
flag is true it rendered out of alphabetical order (ruff-src flagged it
as a fixable isort violation in the circuit-backend E2E lint job). Also had
an extra blank line before API_DESCRIPTION (ruff-format flagged it).

Moved the import above the conditional block so it always sorts correctly
regardless of is_circuit_python_driver, and removed the stray blank line.
Verified against a real Jinja2 render (trim_blocks/lstrip_blocks/
keep_trailing_newline=True, matching copier's defaults) with both ruff
check --select I and ruff format run against the project's actual
.config/ruff.toml.
is_circuit_python_driver was already a template variable, so gate the
resources-plural and no-request-body exemptions directly in
vacuum-ignore.yaml.jinja instead of a post-generation copier _task -
matches weight-sensor-driver's own local vacuum-ignore.yaml (both
exemptions, same justifications), just applied once at the template level
since every circuit-python driver hits the same route shapes.

resources-plural: a generated driver only ever manages one physical
device connection, so /api/driver/* is intentionally singular, not a
REST collection.

no-request-body: DELETE /device-connection removes a device by mDNS
service name with no resource ID in the path, so the body is
unavoidable.

Also register the "driver" tag in OPENAPI_TAGS, next to debug/mDNS under
the same has_circuit_python_backend_template_been_instantiated gate -
circuit-backend's driver_routes.py already tags routes with
tags=["driver"], but nothing had ever registered that tag, so vacuum's
operation-tag-defined fired on every driver route.
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 115a459f-2613-41b4-8bcc-274e750a62bb

📥 Commits

Reviewing files that changed from the base of the PR and between c26519f and d572780.

📒 Files selected for processing (1)
  • template/{% if has_backend %}backend{% endif %}/src/backend_api/app_def.py.jinja

📝 Walkthrough

Walkthrough

The template adds CircuitPython-specific Pyrefly and Vacuum configuration, adds a backend OpenAPI driver tag, and adjusts backend template formatting and schema metadata conditional formatting.

Changes

CircuitPython template support

Layer / File(s) Summary
Driver tooling and validation configuration
copier.yml, template/.config/vacuum-ignore.yaml.jinja
CircuitPython projects add the firmware source directory to Pyrefly’s search path when needed and receive additional Vacuum endpoint exemptions.
Backend OpenAPI template metadata
template/{% if has_backend %}backend{% endif %}/src/backend_api/app_def.py.jinja, template/{% if has_backend %}backend{% endif %}/src/backend_api/fast_api_exception_handlers.py
Backend templates add the driver OpenAPI tag, adjust import and template boundaries, and reformat the schema metadata condition without changing its gate.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: ejfine

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main change: backporting Pyrefly and Vacuum configuration updates.
Description check ✅ Passed The core sections are present and filled; only the Issue/Message thread and Other sections are missing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@copier.yml`:
- Around line 394-403: Update the Pyrefly configuration command in the
is_circuit_python_driver block to match the search-path entry explicitly rather
than checking firmware/src anywhere in the file. After the sed update, enforce
that the first ^search-path = entry contains backend_api/firmware/src and fail
the command when the entry is missing or unchanged; preserve the existing
not-found handling for .config/pyrefly.toml.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2c5e8df6-b220-42ec-b744-dcfb0afecb8d

📥 Commits

Reviewing files that changed from the base of the PR and between 45470d0 and c26519f.

📒 Files selected for processing (4)
  • copier.yml
  • template/.config/vacuum-ignore.yaml.jinja
  • template/{% if has_backend %}backend{% endif %}/src/backend_api/app_def.py.jinja
  • template/{% if has_backend %}backend{% endif %}/src/backend_api/fast_api_exception_handlers.py

Comment thread copier.yml
- "$.paths['/api/driver/device-info-from-serial-port']"
- "$.paths['/api/driver/device-connection']"
- "$.paths['/api/driver/send-raw-command']"
- "$.paths['/api/driver/measurement-types']"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NIT: isn't types already plural?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Issue is not with measurement-types its with driver. Resources plural is ensuring that resources are in fact plural. In this case switching those all our to be drivers felt off specially since some of those debug commands are not using sensor_ids. Wonder if the better answer is we should actually drop driver. And it should become devices and some of the debug ones maybe become something debug specific of /api/devices/debug/ and we just allow list all those. Idk but feels like a future me problem to tweak this api.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah.

I think I was thinking of "driver" originally as more of a "category", because there was were other routes having to do with "mDNS". Yeah, definitely due for some refactoring, and definitely not in this PR

- "$.paths['/api/shutdown'].get.responses"

{% endraw %}{% if backend_uses_graphql %}{% raw %}# /api/graphql's 200 response body is arbitrary JSON shaped by the caller's GraphQL query/GraphiQL page;
{% endraw %}{% if is_circuit_python_driver %}{% raw %}# A generated driver only ever manages a single physical device connection at a time, so its

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the route is id/attribute, then that would be a little common singular pattern a lot right, not just for drivers? We may need a refactor later to make vacuum better suited

@zendern
zendern marked this pull request as ready for review July 28, 2026 02:51
@zendern
zendern merged commit 9a780f9 into main Jul 28, 2026
25 checks passed
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