-
Notifications
You must be signed in to change notification settings - Fork 543
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
bazel-runfiles module always throws ValueError #1631
Comments
@rickeylev Happy to help, but I would need to know whether there have been any intentional changes to the way Python imports are resolved. |
The only thing I can think of relating to imports is some changes to py_proto_library. It was changed to add "virtual imports" (basically the directory where files are put when strip_prefix is used) to the path. |
I can confirm that this issue only occurs when |
Just pushed a branch called |
Sorry for the comment spam, but I've added some additional logging and have a few more findings to share: The import behavior is the same in both https://github.com/bazelbuild/rules_python/blob/main/python/runfiles/runfiles.py#L137-L141 if source_repo is None and self._repo_mapping:
# Look up runfiles using the repository mapping of the caller of the
# current method. If the repo mapping is empty, determining this
# name is not necessary.
source_repo = self.CurrentRepository(frame=2) In both I'm not sure what the "right" thing to do is here since I presume there's an argument that the behavior in |
Just verified that this import behavior can be observed as far back as the I also verified that the |
Thanks for this investigation! |
When I run the reproducer, the
This is why the
@aignas @rickeylev Is this expected? I always assumed that rules_python would not add the source root to |
What version of Python is being used? This sounds like the "script dir is added to sys.path" behavior: https://docs.python.org/3/using/cmdline.html#cmdoption-P Not doing that behavior requires Python 3.11+ |
I was using Python 3.10. That makes sense. @rickeylev I can look into handling this case in the runfiles library for compatibility with Python 3.10 and lower if those versions are meant to be supported. |
…h is needed (#1637) Before this PR there was a typo, that was actually causing the patching function to not use the provided patches. With this change we are finally correctly doing it. After fixing this bug I noticed that `repository_ctx.patch` results in files with `CRLF` on Windows, which made me make the `RECORD` mismatch to be a warning rather than a hard failure to make the CI happy and allow users on Windows to patch wheels but see a warning if they have a multi-platform bazel setup. The `CRLF` endings on Windows issue is fixed in bazelbuild/bazel@07e0d31 Related #1631, #1639.
This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. |
This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?" |
#1634) When using Python 3.10 or earlier, the first `sys.path` entry is the directory containing the script. This can result in modules being loaded from the source root rather than the runfiles root, which the runfiles library previously didn't support. Fixes #1631 --------- Co-authored-by: Ignas Anikevicius <[email protected]> Co-authored-by: Richard Levasseur <[email protected]>
🐞 bug report
Affected Rule
bazel-runfiles
ackageIs this a regression?
Appears to be, we were using
bazel-runfiles
on v0.12.0 with no issueDescription
When running a
py_binary
target, themain
file is executed from within the runfiles tree, but everything imported points back to the original workspace. As a result of this, if you try to usebazel-runfiles
, you're always met with thisValueError
:🔬 Minimal Reproduction
https://github.com/AndrewGuenther/rules_python_1631_repro
Minimal reproduction repository linked above.
🔥 Exception or Error
🌍 Your Environment
Operating System:
Output of
bazel version
:Rules_python version:
Anything else relevant?
The text was updated successfully, but these errors were encountered: