Commit 3512cbe
authored
fix(venv): Don't use dirs as the interpreter (#665)
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
Bazel `execroot/` 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 as `python3` which is ambiguous as to whether the user meant
`./python3` or `python3 from the $PATH`.
The fix here centers on two insights:
- The "real" interpreter can never be a directory (directly fixes the
bug)
- The "real" interpreter's absolute path _must_ have the _same_ absolute
path as whatever `current_exe()` is
### Changes are visible to end-users: yes
- Searched for relevant documentation and updated as needed: yes
- Breaking change (forces users to change their own code or config): no
- Suggested release notes appear below: 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 to `which()` behavior.
### Test plan
- Manual testing1 parent 194a388 commit 3512cbe
1 file changed
+8
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
249 | 252 | | |
250 | 253 | | |
251 | 254 | | |
252 | 255 | | |
253 | 256 | | |
254 | 257 | | |
255 | 258 | | |
| 259 | + | |
| 260 | + | |
256 | 261 | | |
257 | 262 | | |
258 | 263 | | |
| |||
0 commit comments