-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: PyRuntimeInfo provided by py_binary doesn't match PyRuntimeInfo symbol from rules_python #1732
Comments
cc @cpsauer |
I'm somewhat skeptical that this is an issue in rules_python, or at the least is a new issue in a recent version. The logic producing that particular failure message was introduced in Dec 2023 in #1604, however, the prior logic was equivalent (it also required the PyRuntimeInfo provider because it did The error message is also odd: the target name is blank. I don't know how that would happen, but is certainly very strange. |
Hey, thanks for replying back so fast Richard. Context here is that I'd recently moved a (fairly popular) bazel tool we wrote over to rules_python to get hermetic python and pip_parse, but there have been some issues like this one that mean we might have to revert. I'm moderately confident that it's a rules_python (though of course, possibly upstream, bazel core) issue, since this works fine on other platforms (macOS and linux). @axbycc-mark has confirmed the issue with both rules_python 0.28 and 0.29, but that all works fine before our switch to rules_python. Good spot on the missing target name. Is it possible rules_python breaks on Windows if py_binary is called from a macro, as it is here, causing the target to not get picked up somehow? Fairly simple wrapper-macro here otherwise. Would love your help scoping what might be wrong here. I presume we're pretty sure that py_binary works more generally on Windows? @axbycc-mark, to narrow things down, I'll push up a commit adding a non-macro py_binary to test. If you could grab the latest commit of the tool (backlink incoming) and then see if Thanks, |
bazelbuild/rules_python#1732 (comment). Revert when resolved.
Can you try a 0.27.0 or earlier? The 0.28.0 release contains some changes to py_runtime and PyRuntimeInfo, however they should be transparent. re: empty target name: When I say weird, I mean it's an impossible code path, as in, the setting of that attribute involves a non-empty string literal. See https://github.com/bazelbuild/rules_python/blob/main/python/config_settings/transition.bzl#L250 So, worst case, it would have the value "_". The only thing I can think of is a strange interaction when mixing the bazel-bundled py_runtime rule and/or PyRuntimeInfo objects and the rule_python ones. In case it wasn't clear, there are "two" PyRuntimeInfo objects -- the ones defined by rules_python, and the ones defined by Bazel itself. However, the particular code that is failing is compatibility code that is looking for either of those PyRuntimeInfo objects. Hm, maybe a n interaction between workspace and bzlmod? In Bazel 7, bzlmod is enabled by default, but stuff in WORKSPACE can bleed over into bzlmod. Do things work if you set Also, in case it wasn't clear, loading the defs from the versioned repos means they are being bound to that specific python version. i.e. |
@axbycc-mark has the advantage on testing, so I'll defer to him, but it certainly seems like it's hitting that case somehow! Definitely seems worth running the test with --noenable_bzlmod Richard, do you guys have the ability to test on windows and investigate? Re the python version: Yep, got it & intentional. This is a build/dev tool seeking reproducible hermetic python for its implementation, rather than exposing to users. |
Mostly reverts 0e5b1aa Tracking restoration at #168 Please see - #163 - bazelbuild/rules_python#1732 - #165 - (rules_python issue to come) - #166 - bazelbuild/rules_python#1169
Here are my results with the --noenable_bzlmod command from the reproduction repo.
|
^ Oh, interesting! Looks like it's a windows-only rules_python bzlmod interaction issue, then! [That other error is part of the tool, not rules_python, already fixed in a subsequent commit; rules_python is working as expected with --noenable_bzlmod.] |
@axbycc-mark, would you be down to still point to hedronvision/bazel-compile-commands-extractor@40a51d6 and try |
That looks like an error in the refresh_all.py code. removeprefix is a method of python str objects, but it sounds like it has a WindowsPath object from pathlib. It's a fairly easy mistake to make. A function accepting a string path often doesn't notice because it just passes the value onto a lower-level API that understands Path objects. |
^yep, as above! Looks like you were right that the original issue is a windows-specific rules_python bazelmod interaction? |
bzlmod
no bzlmod
|
Thanks for testing! That helps narrow things down: Looks like this has nothing to do with macros or other fancy uses of py_binary. Instead, all is consistent with Richard's hypothesis that rules_python is clashing with itself when brought in via the workspace in Bazel 7 on Windows when bzlmod defaults to being on. Perhaps because a rules_python version is brought in by default as a Bazel tool? For now, ofc, please hop back to the latest commit of the tool where all should work (we've temporarily reverted our rules_python usage until this and some other issues are fixed). Thanks for all your help tracking this down! |
@cpsauer, if you want to things not clash, you should check out WORKSPACE.bzlmod usage. |
^ indeed, but folks are going to use the tool and rules_python from the WORKSPACE for a good while--isn't that a case worth supporting? |
I'm very sure the bug this is talking about is the same one @mattem was able to show a simpler repro for last week, so I'll repurpose this to that. I don't fully understand how these hadron rules are triggering it, but the cause would be the same. The basic issue is the switch to using the rules_python PyRuntimeInfo object overlooked that some users do want to get the PyRuntimeInfo object out of e.g. py_binary. This created the situation where the builtin py_binary rules provide the builtin PyRuntimeInfo object, but the rules_python PyRuntimeInfo binding was pointing to the rules_python PyRuntimeInfo definition. Because providers operate by identity, the two aren't considered the same. I'll switch the PyRuntimeInfo symbol back to the builtin one for now. Instead it'll be guarded by pystar being enabled I have a fix with tests I'm about ready to send for review. It'll go into the next release, planned for once this fix is merged. |
Thanks so much for tackling, @rickeylev! |
@axbycc-mark, could you give that PR's commit a quick test from your workspace, just to make sure that fixes things? Just spin up a quick py_binary and make sure all works (but didn't on the prior release). Thanks so much all 💛 |
…d. (#1748) This fixes the bug where the PyRuntimeInfo symbol rules_python exported wasn't matching the provider identity that `py_binary` actually provided. The basic problem was, when pystar is disabled: * PyRuntimeInfo is the rules_python defined provider * py_binary is `native.py_binary`, which provides only the builtin PyRuntimeInfo provider. Thus, when users loaded the rules_python PyRuntimeInfo symbol, it was referring to a provider that the underlying py_binary didn't actually provide. Pystar is always disabled on Bazel 6.4, and enabling it for Bazel 7 will happen eminently. This typically showed up when users had a custom rule with an attribute definition that used the rules_python PyRuntimeInfo. To fix, only use the rules_python define PyRuntimeInfo if pystar is enabled. This ensures the providers the underlying rules are providing match the symbols that rules_python is exported. * Also fixes `py_binary` and `py_test` to also return the builtin PyRuntimeInfo. This should make the transition from the builtin symbols to the rules_python symbols a bit easier. Fixes #1732
bazelbuild/rules_python#1732 (comment). Revert when resolved.
Mostly reverts hedronvision/bazel-compile-commands-extractor@59dc7ff Tracking restoration at hedronvision/bazel-compile-commands-extractor#168 Please see - hedronvision/bazel-compile-commands-extractor#163 - bazelbuild/rules_python#1732 - hedronvision/bazel-compile-commands-extractor#165 - (rules_python issue to come) - hedronvision/bazel-compile-commands-extractor#166 - bazelbuild/rules_python#1169
🐞 bug report
Affected Rule
The issue is caused by the rule:py_binary rule
Is this a regression?
Yes. Well behaved code loading everything from rules_python (as recommended and desired) stopped working.
A workaround is possible if you control the rule that consumes the target that should provide PyRuntimeInfo: accept both the rules_python PyRuntimeInfo symbol and builtin PyRuntimeInfo provider. When accessing it in rule code, prefer the rules_python one over the bulitin one. When forwarding, forward both if you need compatibility. The gist of the code would look like this:
Description
Using py_binary rule triggers fail() called with error string "target {} does not have rules_python PyRuntimeInfo or builtin PyRuntimeInfo)" on Windows 10
🔬 Minimal Reproduction
Load PyRuntimeInfo and py_binary from rules_python, then try to read the loaded PyRuntimeInfo from the py_binary target.
🔥 Exception or Error
An error about PyRuntimeInfo not being in the target being depended upon.
When it occurs through
provided =...
, it will fail the build pretty early with a Bazel-generated errorIf you have rule code doing
target[PyRuntimeInfo]
, it'll be an error pointing to the line in your rule code looking up that provider.If the version-aware rules are used, it might result in an error like the below:
🌍 Your Environment
Output of
bazel version
:Rules_python version:
0.29.0 for sure. Likely 0.28.x, too, but I didn't check.
Anything else relevant?
Related issue in Hedron's compile-commands-extractor project hedronvision/bazel-compile-commands-extractor#163
The text was updated successfully, but these errors were encountered: