Skip to content

bazel: type check against first-party external repositories - #151

Open
rjhuijsman wants to merge 1 commit into
mainfrom
rjh.mypy-cross-repo-type-checks
Open

bazel: type check against first-party external repositories#151
rjhuijsman wants to merge 1 commit into
mainfrom
rjh.mypy-cross-repo-type-checks

Conversation

@rjhuijsman

@rjhuijsman rjhuijsman commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Our Bazel mypy integration threw away every dependency that lives in an external repository before it hands sources to mypy. 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 in mypy.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-integration to make that possible.

(Note bazel-mypy-integration has not cut a release since 2022, but its successor rules_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.

@aviator-app

aviator-app Bot commented Sep 2, 2026

Copy link
Copy Markdown

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

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.

Copilot AI 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.

🟡 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.

Comment thread bazel/bazel-mypy-integration_first_party_external_repos.patch Outdated
Comment thread bazel/bazel-mypy-integration_first_party_external_repos.patch
@rjhuijsman rjhuijsman self-assigned this Sep 2, 2026
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
@aviator-app

aviator-app Bot commented Sep 2, 2026

Copy link
Copy Markdown

This pull request can't be queued because it's currently a draft.

@rjhuijsman
rjhuijsman marked this pull request as ready for review September 2, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants