Commit 5ea06cb
authored
fix(py_venv): Repair runfiles-relative venv roots (#579)
Due to differences between the MacOS and Linux implementations of
Bazel's sandboxing (reported as #573) the current implementation of
manipulating `argv[0]` to make an interpreter see itself as having a
path of `.runfiles/.../.venv/bin/python3` isn't effective.
Specifically on Linux it appears that we're more eagerly resolving
symlinks.
This means that `bazel-bin/.../*.runfiles/*/.venv/bin/python3` is being
immediately resolved to an `/execroot/bazel-bin/...` entry which
_contains only generated files_. An interpreter with relative path based
import roots within the execroot will be able to import relocated
sources (copied into the venv) but will not be able to import from
source files or external generated files.
Effectively spawning the interpreter is escaping the `.runfiles` tree
which breaks a bunch of our other assumptions.
The repair is to come up with a more portable way to identify the
interpreter without escaping from the runfiles sandbox.
As a solution this PR makes the interpreter shim depend both on the
`$VIRTUAL_ENV` variable which also serves as an anchor to the "real"
`.runfiles` tree. Due to the removals of `realpath` calls in the
`activate` script, it's possible that we could provide fallback behavior
by introspecting `$0`, but that verges on #581 so punting for now.
---
### Changes are visible to end-users: no
### Test plan
- [x] Add imports from unmodified sources to the test cases1 parent 8af732a commit 5ea06cb
File tree
10 files changed
+168
-47
lines changed- py
- private/py_venv
- tests
- py_venv_conflict
- py_venv_image_layer
- tools
- py/src
- venv_shim/src
10 files changed
+168
-47
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | 67 | | |
74 | 68 | | |
75 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
3 | 14 | | |
4 | 15 | | |
5 | 16 | | |
| |||
9 | 20 | | |
10 | 21 | | |
11 | 22 | | |
| 23 | + | |
12 | 24 | | |
13 | 25 | | |
14 | 26 | | |
| |||
18 | 30 | | |
19 | 31 | | |
20 | 32 | | |
| 33 | + | |
21 | 34 | | |
22 | 35 | | |
23 | 36 | | |
| |||
27 | 40 | | |
28 | 41 | | |
29 | 42 | | |
| 43 | + | |
30 | 44 | | |
31 | 45 | | |
32 | 46 | | |
| |||
39 | 53 | | |
40 | 54 | | |
41 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2442 | 2442 | | |
2443 | 2443 | | |
2444 | 2444 | | |
2445 | | - | |
| 2445 | + | |
2446 | 2446 | | |
2447 | 2447 | | |
2448 | 2448 | | |
| |||
2510 | 2510 | | |
2511 | 2511 | | |
2512 | 2512 | | |
2513 | | - | |
2514 | | - | |
2515 | | - | |
2516 | | - | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
2517 | 2517 | | |
2518 | 2518 | | |
2519 | 2519 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2423 | 2423 | | |
2424 | 2424 | | |
2425 | 2425 | | |
2426 | | - | |
| 2426 | + | |
2427 | 2427 | | |
2428 | 2428 | | |
2429 | 2429 | | |
| |||
2491 | 2491 | | |
2492 | 2492 | | |
2493 | 2493 | | |
2494 | | - | |
2495 | | - | |
2496 | | - | |
2497 | | - | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
2498 | 2498 | | |
2499 | 2499 | | |
2500 | 2500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
0 commit comments