fix(bazel): use Label() for deps in py_itf_unittest#118
Open
clanghans wants to merge 1 commit into
Open
Conversation
String labels in legacy macros resolve in the caller's repo context, making @itf_pip invisible to downstream consumers. Label() resolves in the defining module's context instead.
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.
Summary
The
py_itf_unittestmacro passes"@score_itf//:itf"and"@itf_pip//pytest_mock"as string labels in thedepslist ofpy_test. In Bazel's bzlmod, string labels inside legacy (def-based) macros are resolved in the caller's repository context, not the defining module's. This means@itf_pipis looked up in the downstream consumer's repo, where it does not exist.The fix wraps both labels with
Label(), which is evaluated at.bzlload time and resolves in score_itf's module context, whereitf_pipis always defined.This is consistent with how
pytest_bootstrapandpytest_configare already handled in the same file (lines 33-35).Problem
Any downstream module that uses
py_itf_unittestfails at analysis time:The only workaround is for every consumer to add
use_repo(pip, "itf_pip")to their ownMODULE.bazel, leaking an internal implementation detail of score_itf into all downstream modules.Benefits
Downstream consumers no longer need to know about
@itf_pip. The pip hub name is an internal detail of score_itf. Consumers should only needbazel_dep(name = "score_itf", ...)to use any public macro.Consistent with the rest of the file.
pytest_bootstrapandpytest_configalready useLabel(). Thedepslist was the only place still using raw strings for cross-module references.No behavioral change for score_itf's own tests.
Label("@itf_pip//...")resolves to the same target within score_itf as the string"@itf_pip//..."does today. The fix only changes resolution behavior when the macro is called from a different module.