-
-
Notifications
You must be signed in to change notification settings - Fork 650
fix (venv_site_packages): Fix wrong runfiles.symlinks when py_binary is not in root module #3505
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
fix (venv_site_packages): Fix wrong runfiles.symlinks when py_binary is not in root module #3505
Conversation
Summary of ChangesHello @shayanhoshyari, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical issue affecting Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request aims to fix an issue with venv_site_packages for py_binary targets in non-root modules by switching from symlinks to root_symlinks. The change in py_executable.bzl is correct. However, the corresponding change in venv_runfiles.bzl to construct the symlink path is incorrect. It will fail for targets in the main repository by omitting the workspace name prefix, and for external repositories by not stripping the '@' prefix from the repository name. I've left a critical comment with a suggested fix for this issue.
- Use root_symlinks instead and add the repo name of owner - Gonna make a PR to see if tests pass and in meantime will look for a good test.
0131daa to
6b9d146
Compare
|
Thanks for the fix. Overall it LGTM. I added the basics of a test to verify it, but have run out of time to fully incorporate the test. I was manually testing by running I think all that's left is to change the venv_bin to a py_test, then put a test_suite() somewhere that refers to it (tests/venvs_site_packages_libs would be a good a place) |
|
Thanks for the quick response.
Nevermind, needs a analysis_test due to #3505 (comment). I will try to do it tomorrow. |
7eeebdc to
1b6fe66
Compare
1b6fe66 to
9e45922
Compare
| # Check the links exist in the correct place. | ||
| echo "[*] Testing existence of symlinks in the right place" | ||
| ensure_link ./other+/_venv_bin.venv/lib/python3.13/site-packages/nspkg/subnspkg/delta/__init__.py | ||
| ensure_link ./other+/_venv_bin.venv/lib/python3.13/site-packages/nspkg/subnspkg/gamma/__init__.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems bazel 7 calls it other/ rather than other+/
https://storage.googleapis.com/bazel-untrusted-buildkite-artifacts/019bac0c-4189-4c07-8d12-8904cd464fa0/tests/venv_site_packages_libs/py_binary_other_module_test/test_attempts/attempt_1.log
Ok really need an analysis test here for this part. Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create an analysis test if you really want (I think there's several in the venv_site_packages_libs directory somewhere you can base upon; you can just pass the venv_bin binary as the input and inspect its runfiles).
That said, I would just check that the modules are importable instead of their exact paths. The exact paths are somewhat just an implementation detail. The key attribute we care about is if things are importable. If you still want to check the paths then just do a looser match, e.g. other*/*/site-packages/nspkg/subnspkg/gamma/__init__.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just check that the modules are importable instead of their exact paths
Oh even easier. Ok I will do this. Since the execution of the binary checks this already, I think I just need to delete these lines that check the files. And add some better error message if imports fail in the binary.
|
I've cleaned up and simplified the test. |
music to my ears. thanks. |
…is not in root module (bazel-contrib#3505) When: 1) venv_site_packages is on 2) we have a py_binary in a non-root module (e.g. a tool used in rules), and it uses python deps that result in usage of runfiles.symlinks, the `ctx.runfile` based symlinks end up going in the wrong folder (`_main`), while the `ctx.actions.symlink(...)` files go in the right place. This results in an invalid `venv` and import errors. The reason is that `actions.symlinks` always go to the `_main` module, as [Bazel docs explain](https://bazel.build/extending/rules#runfiles_symlinks). To send symlinks to other modules, one needs to use root_symlinks and prefix them with the right module name. Fixes: bazel-contrib#3503 --------- Co-authored-by: Shayan Hoshyari <hoshyari@adobe.com> Co-authored-by: Richard Levasseur <rlevasseur@google.com> (cherry picked from commit f9992f7)
When: 1) venv_site_packages is on 2) we have a py_binary in a non-root module (e.g. a tool used in rules), and it uses python deps that result in usage of runfiles.symlinks, the
ctx.runfilebased symlinks end up going in the wrong folder (_main), while thectx.actions.symlink(...)files go in the right place. This results in an invalidvenvand import errors.The reason is that
actions.symlinksalways go to the_mainmodule, as Bazel docs explain. To send symlinks to other modules, one needs to use root_symlinks and prefix them with the right module name.Fixes: #3503