Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 83 additions & 1 deletion Cargo.Bazel.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "eb371dc49c5639c18e7f0415686de673ae7f83a972b6fd8823550485f5f63bea",
"checksum": "81528401c6d6fde79ca22def4e50d7ebc47f7f182a83a106d38e9e1279da39a5",
"crates": {
"addr2line 0.24.2": {
"name": "addr2line",
Expand Down Expand Up @@ -10864,6 +10864,10 @@
"id": "relative-path 1.9.3",
"target": "relative_path"
},
{
"id": "sha256 1.6.0",
"target": "sha256"
},
{
"id": "tempfile 3.13.0",
"target": "tempfile"
Expand Down Expand Up @@ -16836,6 +16840,83 @@
],
"license_file": "LICENSE-APACHE"
},
"sha256 1.6.0": {
"name": "sha256",
"version": "1.6.0",
"package_url": "https://github.com/baoyachi/sha256-rs",
"repository": {
"Http": {
"url": "https://static.crates.io/crates/sha256/1.6.0/download",
"sha256": "f880fc8562bdeb709793f00eb42a2ad0e672c4f883bbe59122b926eca935c8f6"
}
},
"targets": [
{
"Library": {
"crate_name": "sha256",
"crate_root": "src/lib.rs",
"srcs": {
"allow_empty": true,
"include": [
"**/*.rs"
]
}
}
}
],
"library_target_name": "sha256",
"common_attrs": {
"compile_data_glob": [
"**"
],
"crate_features": {
"common": [
"async",
"default",
"tokio"
],
"selects": {}
},
"deps": {
"common": [
{
"id": "bytes 1.8.0",
"target": "bytes"
},
{
"id": "hex 0.4.3",
"target": "hex"
},
{
"id": "sha2 0.10.8",
"target": "sha2"
},
{
"id": "tokio 1.41.0",
"target": "tokio"
}
],
"selects": {}
},
"edition": "2018",
"proc_macro_deps": {
"common": [
{
"id": "async-trait 0.1.83",
"target": "async_trait"
}
],
"selects": {}
},
"version": "1.6.0"
},
"license": "MIT OR Apache-2.0",
"license_ids": [
"Apache-2.0",
"MIT"
],
"license_file": "LICENSE-APACHE"
},
"shell-escape 0.1.5": {
"name": "shell-escape",
"version": "0.1.5",
Expand Down Expand Up @@ -27627,6 +27708,7 @@
"miette 7.2.0",
"pathdiff 0.2.3",
"relative-path 1.9.3",
"sha256 1.6.0",
"tempfile 3.13.0",
"thiserror 1.0.65",
"uv-cache 0.0.1",
Expand Down
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions py/tests/py_venv_conflict/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//py/unstable:defs.bzl", "py_venv")

py_venv(
name = "test_venv_error",
package_collisions = "error",
tags = [
"known-to-fail",
"manual",
],
deps = [
"//py/tests/py_venv_conflict/a",
"//py/tests/py_venv_conflict/b",
],
)

py_venv(
name = "test_venv_warning",
package_collisions = "warning",
deps = [
"//py/tests/py_venv_conflict/a",
"//py/tests/py_venv_conflict/b",
],
)

py_venv(
name = "test_venv_ignore",
package_collisions = "ignore",
deps = [
"//py/tests/py_venv_conflict/a",
"//py/tests/py_venv_conflict/b",
],
)

build_test(
name = "py_venv_conflict",
targets = [
":test_venv_warning",
":test_venv_ignore",
],
)
13 changes: 13 additions & 0 deletions py/tests/py_venv_conflict/a/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("//py:defs.bzl", "py_library")

py_library(
name = "a",
srcs = [
"site-packages/conflict.py",
"site-packages/noconflict.py",
],
imports = [
"site-packages",
],
visibility = ["//py/tests/py_venv_conflict:__pkg__"],
)
4 changes: 4 additions & 0 deletions py/tests/py_venv_conflict/a/site-packages/conflict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python3

def conflict():
return "a"
4 changes: 4 additions & 0 deletions py/tests/py_venv_conflict/a/site-packages/noconflict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python3

def noconflict():
return 1
13 changes: 13 additions & 0 deletions py/tests/py_venv_conflict/b/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("//py:defs.bzl", "py_library")

py_library(
name = "b",
srcs = [
"site-packages/conflict.py",
"site-packages/noconflict.py",
],
imports = [
"site-packages",
],
visibility = ["//py/tests/py_venv_conflict:__pkg__"],
)
4 changes: 4 additions & 0 deletions py/tests/py_venv_conflict/b/site-packages/conflict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python3

def conflict():
return "b"
4 changes: 4 additions & 0 deletions py/tests/py_venv_conflict/b/site-packages/noconflict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python3

def noconflict():
return 1
1 change: 1 addition & 0 deletions py/tools/py/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rust_library(
"@crate_index//:itertools",
"@crate_index//:miette",
"@crate_index//:pathdiff",
"@crate_index//:sha256",
"@crate_index//:tempfile",
"@crate_index//:thiserror",
"@crate_index//:uv-cache",
Expand Down
1 change: 1 addition & 0 deletions py/tools/py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ itertools = { workspace = true }
miette = { workspace = true }
pathdiff = "0.2.3"
relative-path = "1.9.3"
sha256 = "1.6.0"
tempfile = { workspace = true }
thiserror = { workspace = true }
uv-cache = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion py/tools/py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ pub mod venv;
pub use unpack::unpack_wheel;
pub use venv::create_venv;

pub use pth::{PthFile, SymlinkCollisionResolutionStrategy};
pub use pth::{CollisionResolutionStrategy, PthFile};
14 changes: 7 additions & 7 deletions py/tools/py/src/pth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ from .runfiles import *

/// Strategy that will be used when creating the virtual env symlink and
/// a collision is found.
#[derive(Default, Debug)]
pub enum SymlinkCollisionResolutionStrategy {
#[derive(Default, Debug, PartialEq)]
pub enum CollisionResolutionStrategy {
/// Collisions cause a hard error.
#[default]
Error,
Expand All @@ -49,7 +49,7 @@ pub struct SitePackageOptions {
pub dest: PathBuf,

/// Collision strategy determining the action taken when sylinks in the venv collide.
pub collision_strategy: SymlinkCollisionResolutionStrategy,
pub collision_strategy: CollisionResolutionStrategy,
}

pub struct PthFile {
Expand Down Expand Up @@ -121,7 +121,7 @@ pub fn create_symlinks(
dir: &Path,
root_dir: &Path,
dst_dir: &Path,
collision_strategy: &SymlinkCollisionResolutionStrategy,
collision_strategy: &CollisionResolutionStrategy,
) -> miette::Result<()> {
// Create this directory at the destination.
let tgt_dir = dst_dir.join(dir.strip_prefix(root_dir).unwrap());
Expand Down Expand Up @@ -176,7 +176,7 @@ fn create_symlink(
e: &DirEntry,
root_dir: &Path,
dst_dir: &Path,
collision_strategy: &SymlinkCollisionResolutionStrategy,
collision_strategy: &CollisionResolutionStrategy,
) -> miette::Result<()> {
let tgt = e.path();
let link = dst_dir.join(tgt.strip_prefix(root_dir).unwrap());
Expand Down Expand Up @@ -232,7 +232,7 @@ fn create_symlink(
}

match collision_strategy {
SymlinkCollisionResolutionStrategy::LastWins(warn) => {
CollisionResolutionStrategy::LastWins(warn) => {
fs::remove_file(&link)
.into_diagnostic()
.wrap_err(
Expand All @@ -248,7 +248,7 @@ fn create_symlink(
eprintln!("{:?}", conflicts);
}
}
SymlinkCollisionResolutionStrategy::Error => {
CollisionResolutionStrategy::Error => {
// If the link already exists, then there is going to be a conflict.
let conflicts = conflict_report(&link, &tgt, Severity::Error);
return Err(conflicts);
Expand Down
Loading
Loading