fix(venv): Don't use dirs as the interpreter #665
Merged
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.
Fixes #664
On Linux and MacOS, the
current_exe()
path has likely been realpath-ed by the system or the libc somewhere along the line. This means that if the user types.venv/bin/python3
, the entire symlink chain that may point into will be chased and we'll get a path somewhere inside the Bazelexecroot/
output tree. Critically on Linux this symlink tree goes past the.runfiles/
directory entry the user intended to create a symlink to, which prevents our interpreter shim from delegating to a.runfiles/
packaged Python like the user desired.In order for us to resolve "just enough" symlinks to identify the
.runfiles/
tree, we need to manually resolve the path of the current executable. Previously doing so would create a false positive if there was a./python
or./python3
directory, and the interpreter shim was invoked aspython3
which is ambiguous as to whether the user meant./python3
orpython3 from the $PATH
.The fix here centers on two insights:
current_exe()
isChanges are visible to end-users: yes
Fixed a bug which would cause the interpreter shims to identify
./python3/
or./python/
(directories) as the real path of the interpreter "python3" rather than falling back towhich()
behavior.Test plan