Skip to content

Commit 3ff3b51

Browse files
authored
fix(py_venv): Implement collision handling (#578)
This patch extends the new static venv machinery to handle conflicts in the logical venv path. Support is preliminary but complete, a multi-pass venv creation strategy would be better for producing comprehensive errors rather than forcing users to whack-a-mole. Fixes #575 ### 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 ### Test plan - [x] New test cases added - [x] `error` mode conflicting venv is broken - [x] `warn` mode conflicting venv produces a warning - [x] `ignore` mode conflicting venv is silent - [x] "Conflicting" files with same content are handled silently
1 parent a699063 commit 3ff3b51

File tree

19 files changed

+281
-74
lines changed

19 files changed

+281
-74
lines changed

Cargo.Bazel.lock

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "eb371dc49c5639c18e7f0415686de673ae7f83a972b6fd8823550485f5f63bea",
2+
"checksum": "81528401c6d6fde79ca22def4e50d7ebc47f7f182a83a106d38e9e1279da39a5",
33
"crates": {
44
"addr2line 0.24.2": {
55
"name": "addr2line",
@@ -10864,6 +10864,10 @@
1086410864
"id": "relative-path 1.9.3",
1086510865
"target": "relative_path"
1086610866
},
10867+
{
10868+
"id": "sha256 1.6.0",
10869+
"target": "sha256"
10870+
},
1086710871
{
1086810872
"id": "tempfile 3.13.0",
1086910873
"target": "tempfile"
@@ -16836,6 +16840,83 @@
1683616840
],
1683716841
"license_file": "LICENSE-APACHE"
1683816842
},
16843+
"sha256 1.6.0": {
16844+
"name": "sha256",
16845+
"version": "1.6.0",
16846+
"package_url": "https://github.com/baoyachi/sha256-rs",
16847+
"repository": {
16848+
"Http": {
16849+
"url": "https://static.crates.io/crates/sha256/1.6.0/download",
16850+
"sha256": "f880fc8562bdeb709793f00eb42a2ad0e672c4f883bbe59122b926eca935c8f6"
16851+
}
16852+
},
16853+
"targets": [
16854+
{
16855+
"Library": {
16856+
"crate_name": "sha256",
16857+
"crate_root": "src/lib.rs",
16858+
"srcs": {
16859+
"allow_empty": true,
16860+
"include": [
16861+
"**/*.rs"
16862+
]
16863+
}
16864+
}
16865+
}
16866+
],
16867+
"library_target_name": "sha256",
16868+
"common_attrs": {
16869+
"compile_data_glob": [
16870+
"**"
16871+
],
16872+
"crate_features": {
16873+
"common": [
16874+
"async",
16875+
"default",
16876+
"tokio"
16877+
],
16878+
"selects": {}
16879+
},
16880+
"deps": {
16881+
"common": [
16882+
{
16883+
"id": "bytes 1.8.0",
16884+
"target": "bytes"
16885+
},
16886+
{
16887+
"id": "hex 0.4.3",
16888+
"target": "hex"
16889+
},
16890+
{
16891+
"id": "sha2 0.10.8",
16892+
"target": "sha2"
16893+
},
16894+
{
16895+
"id": "tokio 1.41.0",
16896+
"target": "tokio"
16897+
}
16898+
],
16899+
"selects": {}
16900+
},
16901+
"edition": "2018",
16902+
"proc_macro_deps": {
16903+
"common": [
16904+
{
16905+
"id": "async-trait 0.1.83",
16906+
"target": "async_trait"
16907+
}
16908+
],
16909+
"selects": {}
16910+
},
16911+
"version": "1.6.0"
16912+
},
16913+
"license": "MIT OR Apache-2.0",
16914+
"license_ids": [
16915+
"Apache-2.0",
16916+
"MIT"
16917+
],
16918+
"license_file": "LICENSE-APACHE"
16919+
},
1683916920
"shell-escape 0.1.5": {
1684016921
"name": "shell-escape",
1684116922
"version": "0.1.5",
@@ -27627,6 +27708,7 @@
2762727708
"miette 7.2.0",
2762827709
"pathdiff 0.2.3",
2762927710
"relative-path 1.9.3",
27711+
"sha256 1.6.0",
2763027712
"tempfile 3.13.0",
2763127713
"thiserror 1.0.65",
2763227714
"uv-cache 0.0.1",

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
2+
load("//py/unstable:defs.bzl", "py_venv")
3+
4+
py_venv(
5+
name = "test_venv_error",
6+
package_collisions = "error",
7+
tags = [
8+
"known-to-fail",
9+
"manual",
10+
],
11+
deps = [
12+
"//py/tests/py_venv_conflict/a",
13+
"//py/tests/py_venv_conflict/b",
14+
],
15+
)
16+
17+
py_venv(
18+
name = "test_venv_warning",
19+
package_collisions = "warning",
20+
deps = [
21+
"//py/tests/py_venv_conflict/a",
22+
"//py/tests/py_venv_conflict/b",
23+
],
24+
)
25+
26+
py_venv(
27+
name = "test_venv_ignore",
28+
package_collisions = "ignore",
29+
deps = [
30+
"//py/tests/py_venv_conflict/a",
31+
"//py/tests/py_venv_conflict/b",
32+
],
33+
)
34+
35+
build_test(
36+
name = "py_venv_conflict",
37+
targets = [
38+
":test_venv_warning",
39+
":test_venv_ignore",
40+
],
41+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("//py:defs.bzl", "py_library")
2+
3+
py_library(
4+
name = "a",
5+
srcs = [
6+
"site-packages/conflict.py",
7+
"site-packages/noconflict.py",
8+
],
9+
imports = [
10+
"site-packages",
11+
],
12+
visibility = ["//py/tests/py_venv_conflict:__pkg__"],
13+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python3
2+
3+
def conflict():
4+
return "a"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python3
2+
3+
def noconflict():
4+
return 1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("//py:defs.bzl", "py_library")
2+
3+
py_library(
4+
name = "b",
5+
srcs = [
6+
"site-packages/conflict.py",
7+
"site-packages/noconflict.py",
8+
],
9+
imports = [
10+
"site-packages",
11+
],
12+
visibility = ["//py/tests/py_venv_conflict:__pkg__"],
13+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python3
2+
3+
def conflict():
4+
return "b"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python3
2+
3+
def noconflict():
4+
return 1

py/tools/py/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ rust_library(
2222
"@crate_index//:itertools",
2323
"@crate_index//:miette",
2424
"@crate_index//:pathdiff",
25+
"@crate_index//:sha256",
2526
"@crate_index//:tempfile",
2627
"@crate_index//:thiserror",
2728
"@crate_index//:uv-cache",

0 commit comments

Comments
 (0)