build: add static type checking for runfiles with rules_pyrefly - #4009
Merged
rickeylev merged 25 commits intoAug 7, 2026
Conversation
Integrates rules_pyrefly in MODULE.bazel, defines the Pyrefly aspect in tools/pyrefly.bzl with --config=pyrefly in .bazelrc, and addresses a type override suppression in python/runfiles/runfiles.py.
Relocates pyrefly.bzl into tools/private and updates the aspect target reference in .bazelrc.
Relocates pyrefly.bzl under tools/private/pyrefly and updates .bazelrc label reference.
Synchronizes BUILD.bazel with Gazelle generated rules.
Updates the aspect reference in .bazelrc to use the tools/private/pyrefly package path.
…ate BUILD files Cleans up unused pyrefly bzl_library definitions now that pyrefly.bzl lives in tools/private/pyrefly.
Removes the unnecessary bzl_library target and BUILD.bazel from tools/private/pyrefly, updating .bazelrc to reference //tools/private:pyrefly/pyrefly.bzl%pyrefly_aspect.
…ype checking Implements pyrefly_check in tools/private:pyrefly/pyrefly.bzl taking targets as a label list, and instantiates runfiles_check in tests/runfiles/BUILD.bazel targeting //python/runfiles:runfiles.
… update load labels
…d use default_visibility in tools/private/pyrefly/BUILD.bazel
Defines pyrefly_check_test with test = True so running bazel test //tests/runfiles/... automatically discovers and executes runfiles_check as a test target.
Restores pyrefly_check as a build rule in tools/private/pyrefly/pyrefly.bzl and tests it using standard build_test in tests/runfiles/BUILD.bazel.
Encapsulates pyrefly_check rule and build_test into a reusable pyrefly_check_test macro in tools/private/pyrefly/pyrefly.bzl.
Relocates the pyrefly test helper package from tools/private/pyrefly to tests/support/pyrefly and updates load references.
Replaces the custom pyrefly_check wrapper rule with rules_pyrefly's native opt_in_tags feature. Applies pyrefly_aspect globally via .bazelrc while tagging //python/runfiles:runfiles for opt-in static type checking.
Prevents WORKSPACE-mode (non-Bzlmod) builds from failing due to unresolved @rules_pyrefly repository references while preserving opt-in tag-based static type checking under Bzlmod.
Top-level if statements are forbidden in Bazel BUILD files. Moving the BZLMOD_ENABLED check inside the pyrefly_check_test macro definition in pyrefly.bzl ensures clean BUILD file evaluation while preserving Bzlmod-only target generation.
Adds rules_pyrefly repository definition to rules_python_internal_deps in internal_dev_deps.bzl so package loading succeeds during WORKSPACE mode builds. Removes non-existent bzl_library dependency target.
rickeylev
marked this pull request as ready for review
August 6, 2026 11:09
rickeylev
enabled auto-merge
August 6, 2026 11:09
Clarifies in pyrefly.bzl that Pyrefly type checking does not support WORKSPACE mode and exits early when Bzlmod is not enabled.
aignas
approved these changes
Aug 7, 2026
rickeylev
force-pushed
the
use_pyrefly_runfiles_check
branch
3 times, most recently
from
August 7, 2026 02:47
7ee3132 to
000a93d
Compare
Registers rules_pyrefly_stub in internal_dev_deps.bzl for WORKSPACE mode so load() statements resolve, and adds global aspect flag to .bazelrc to apply Pyrefly static type checking across tagged targets.
rickeylev
force-pushed
the
use_pyrefly_runfiles_check
branch
from
August 7, 2026 02:49
000a93d to
43649e1
Compare
rickeylev
enabled auto-merge
August 7, 2026 02:50
rickeylev
disabled auto-merge
August 7, 2026 02:50
Removes the macro target invocation now that Pyrefly type checking is applied globally via aspect on tagged targets.
rickeylev
enabled auto-merge
August 7, 2026 02:51
rickeylev
disabled auto-merge
August 7, 2026 02:52
Removes the unused macro and rule definitions, leaving only pyrefly_aspect in tests/support/pyrefly/pyrefly.bzl.
Adds an always-on workspace rule prohibiting the use of auth tokens in command line arguments.
rickeylev
enabled auto-merge
August 7, 2026 02:56
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Aug 7, 2026
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.
Enable static type verification for the runfiles library using the
rules_pyrefly ruleset.
To ensure hermetic type safety across Bazel runfiles utilities, this
configures rules_pyrefly's Bzlmod dev toolchain, tags the runfiles
target with
tags = ["pyrefly"], and enables global aspect evaluationin .bazelrc via
--aspects=//tests/support/pyrefly:pyrefly.bzl%pyrefly_aspect.To support WORKSPACE mode builds without breaking dependency resolution,
a no-op stub repository for rules_pyrefly is defined under
tests/modules/rules_pyrefly_stub and registered in internal_dev_deps.bzl.
Under Bzlmod, the aspect performs static type checking on tagged targets,
while under WORKSPACE mode, the stub aspect evaluates cleanly as a no-op.