Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the issue with pruning the last package in pip tree #4652

Merged
merged 1 commit into from
Jun 29, 2024
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
10 changes: 4 additions & 6 deletions crates/uv/src/commands/pip/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,6 @@ impl<'a> DisplayDependencyGraph<'a> {
return Vec::new();
}

// Short-circuit if the current package is given in the prune list.
if self.prune.contains(installed_dist.name()) {
return Vec::new();
}

let package_name = installed_dist.name().to_string();
let is_visited = visited.contains(&package_name);
let line = format!("{} v{}", package_name, installed_dist.version());
Expand All @@ -185,7 +180,10 @@ impl<'a> DisplayDependencyGraph<'a> {

path.push(package_name.clone());
visited.insert(package_name.clone());
let required_packages = required_with_no_extra(installed_dist, self.markers);
let required_packages = required_with_no_extra(installed_dist, self.markers)
.into_iter()
.filter(|p| !self.prune.contains(&p.name))
.collect::<Vec<_>>();
for (index, required_package) in required_packages.iter().enumerate() {
// Skip if the current package is not one of the installed distributions.
if !self
Expand Down
43 changes: 43 additions & 0 deletions crates/uv/tests/pip_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,49 @@ fn no_package() {
);
}

#[test]
fn prune_last_in_the_subgroup() {
let context = TestContext::new("3.12");

let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str("requests==2.31.0").unwrap();

uv_snapshot!(context
.pip_install()
.arg("-r")
.arg("requirements.txt")
.arg("--strict"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 5 packages in [TIME]
Prepared 5 packages in [TIME]
Installed 5 packages in [TIME]
+ certifi==2024.2.2
+ charset-normalizer==3.3.2
+ idna==3.6
+ requests==2.31.0
+ urllib3==2.2.1
"###
);

context.assert_command("import requests").success();
uv_snapshot!(context.filters(), tree_command(&context).arg("--prune").arg("certifi"), @r###"
success: true
exit_code: 0
----- stdout -----
requests v2.31.0
├── charset-normalizer v3.3.2
├── idna v3.6
└── urllib3 v2.2.1

----- stderr -----
"###
);
}

#[test]
fn single_package() {
let context = TestContext::new("3.12");
Expand Down
Loading