-
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
fix: correctly obtain relative path required for the venv created by --bootstrap_impl=script
#2439
fix: correctly obtain relative path required for the venv created by --bootstrap_impl=script
#2439
Conversation
…ipt bootstrap implementation
The following rules were tested and validated:
|
--bootstrap_impl=script
--bootstrap_impl=script
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.
Ah, hah. I'm guessing the reason this worked in CI is the path depth of the test programs was the same as the path depth of the underlying interpreter? 😂
Thanks for the PR!
The relative path logic looks overly complicated, though? All it has to do is calculate how many up-escapes are needed to get from the {prefix}.venv/bin/python3
location to the runfiles root, then append the ../
-stripped value of the actual interpreter to that.
I think the ../
prefixed part of e.g. runtime.interpreter.short_path
(or any .short_path
) is there in lieu of external/
, and represents "go up one dir from the main repo" (because its referring to some external repo).
Yeah it's kinda complicated (don't like it) - I wasn't sure what were all the edge cases here, so writing it generically was the only way I knew how to do it. Would something like this suffice? venv_bin_dir = paths.dirname(interpreter.short_path)
if venv_bin_dir.startswith("../"):
escapes = venv_bin_dir.count("/") - 1
else:
escapes = venv_bin_dir.count("/") + 1
parent = "/".join([".."] * escapes)
rel_path = parent + "/" + interpreter_actual_path
ctx.actions.symlink(output = interpreter, target_path = rel_path) (Wouldn't support a Happy for you to replace this with whatever you see fit too. :) |
…hs instead of main-repo-root relative paths
… real examples to use runfiles-root relative paths
Yes, it should. I pushed a change that basically did that -- compute the relative path between two runfiles-root-relative paths instead of main-repo-relative paths. I kept the relative_path function since I like that it will compute a minimum relative-path. I also pushed a test to reproduce the problem. It creates a test in a much more deeply nested directory than where the actual interpreter is. As well as some other cleanup. |
I think you got them all, so good job 🙂 . That |
… update real examples to use runfiles-root relative paths
Co-authored-by: Ignas Anikevicius <[email protected]>
The CI failure is due to bazel-contrib/bazel_features#82, so I'll force-merge past it. |
Ah, actually, I don't think I can force-merge because I'm not an admin. I'll ask about getting admin back. Otherwise, we can just switch the "upcoming bazel" CI to 8rc2 instead of 8rc3 |
@rickeylev Thanks for the changes. :) |
Apologies. Just noticed that
|
Computing the relative path from the venv interpreter to the underlying interpreter was
incorrectly using the actual interpreter's directory depth, not the venv interpreter's
directory depth, when computing the distance from the venv interpreter to the runfiles root.
The net effect is the correct relative path would only be computed for binaries with
the same directory depth as the actual interpreter (e.g. 2).
This went undetected in CI because the tests for this logic just happen to have the
same directory depth as the actual interpreter used.
To fix, compute the relative path to the runfiles root using the venv interpreter
directory. Also added a test in a more nested directory to test this case.
Along the way:
for the actual interpreter, as intended.
Fixes #2169