bazel: type check against first-party external repositories - #151
bazel: type check against first-party external repositories#151rjhuijsman wants to merge 1 commit into
bazel: type check against first-party external repositories#151Conversation
Current Aviator status
This PR is not ready to merge (currently in state pending): this PR has not been approved. Pending Status Checks
See the real-time status of this PR on the
Aviator webapp.
Use the Aviator Chrome Extension
to see the status of your PR within GitHub.
|
There was a problem hiding this comment.
🟡 Changes recommended
External path handling misclassifies some workspace files and breaks mypy_test runfile resolution.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds first-party external repository support to Bazel’s mypy integration for cross-repository type checking.
Changes:
- Adds and configures an external-repository allowlist.
- Includes allowlisted sources in mypy resolution without directly checking them.
File summaries
| File | Description |
|---|---|
.bazelrc |
Configures Reboot as first-party. |
bazel/repos.bzl |
Applies the new integration patch. |
bazel/bazel-mypy-integration_first_party_external_repos.patch |
Implements external-source resolution. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Our `mypy` integration threw away every dependency that lives in an external Bazel repository before handing sources to `mypy`: `_extract_transitive_deps` skipped deps whose `workspace_root` starts with `external/`, and the source list then dropped any file with such a path. That is the right call for third-party code, but it also hid this repository from the `mono` repository, which consumes it as `@com_github_reboot_dev_reboot` while importing it under the module names it has here - `reboot.*`, `rbt.*`, `log.*`. Those imports resolved to nothing there, so `mono`'s `mypy.ini` silenced them with `ignore_missing_imports` and every call into this library was checked against `Any`. The `TypeError` that motivated reboot-dev/mono#5679 - a keyword argument this library had moved into a wrapper object - therefore surfaced forty minutes into a cluster bring-up rather than at build time. Repositories named in the new `--@mypy_integration//:first_party_external_repos` flag are now resolved. Their files stay out of the checked source list, because errors in them belong to their own build, but they become inputs of the action and go onto `MYPYPATH` and `--package-root` at the directory their repository is rooted at: `external/<repo>` for sources and `bazel-out/<config>/bin/external/<repo>` for generated code. `explicit_package_bases`, which we already set, makes `mypy` name a module by its path relative to the nearest `MYPYPATH` entry, so `external/com_github_reboot_dev_reboot/reboot/aio/applications.py` becomes `reboot.aio.applications` instead of `external.com_github_reboot_dev_reboot.reboot.aio.applications`. The flag is set in this repository's `.bazelrc` because that is the file `mono` symlinks as its own. This repository has no first-party external repository of its own, so naming one costs it nothing. Upgrading to `rules_mypy`, the successor to `bazel-mypy-integration`, would not have helped: it also returns early for any target whose `workspace_root` is non-empty, and the only external directories it puts on `MYPYPATH` are `site-packages` ones and those named by a dep's `imports`, neither of which describes a repository like this one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016qY16VqAe1y1dQuGEnqv72
d41b980 to
16c1e71
Compare
|
This pull request can't be queued because it's currently a draft. |
Our Bazel
mypyintegration threw away every dependency that lives in an external repository before it hands sources tomypy. That behavior is right for third-party code, since we don't want errors inside e.g. gRPC's library to become errors for our project. However, as an unfortunate side-effect that means that our usage of external code also isn't checkable - we must add many ignore-entries inmypy.ini.While the trade-off seems right for third-party code, for our own first-party repos the better tradeoff would be the opposite: we're OK with a double-check of external repos, if that means that we get proper cross-repo type checks. This commit adds a patch to our
bazel-mypy-integrationto make that possible.(Note
bazel-mypy-integrationhas not cut a release since 2022, but its successorrules_mypy, also does not solve this problem and is built for Bzlmod, which we don't support yet)The cross-repo checks this patch makes possible have caught several real bugs in our code; follow-on PRs in other repos will fix those.