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

Implement pip list --verbose #9839

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
79 changes: 64 additions & 15 deletions crates/uv/src/commands/pip/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,48 @@ pub(crate) async fn pip_list(
results
};

let verbose = true; // TODO: this should be a flag
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we thread this through to the list command, and do we still want the verbosity flag to apply to uv in general?


match format {
ListFormat::Json => {
let rows = results
.iter()
.copied()
.map(|dist| Entry {
name: dist.name().clone(),
version: dist.version().clone(),
latest_version: latest
.get(dist.name())
.and_then(|filename| filename.as_ref())
.map(DistFilename::version)
.cloned(),
latest_filetype: latest
.get(dist.name())
.and_then(|filename| filename.as_ref())
.map(FileType::from),
editable_project_location: dist
.as_editable()
.map(|url| url.to_file_path().unwrap().simplified_display().to_string()),
.map(|dist| {
let location = if verbose && dist.path().parent().is_some() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pip lists the location where the package is installed, for example [SITE_PACKAGES], whereas dist.path() is something like [SITE_PACKAGES]/pulumi-3.143.0.dist-info.

The parent() bit mostly works for this (although we get a trailing /), but it's probably not quite right for all types of installations.

Some(dist.path().parent().unwrap().simplified_display().to_string())
} else {
None
};
let installer = if verbose {
match dist.installer() {
Ok(installer) => installer,
Err(err) => {
println!("Error: {}", err);
None
}
}
} else {
None
};
Entry {
name: dist.name().clone(),
version: dist.version().clone(),
location,
installer,
latest_version: latest
.get(dist.name())
.and_then(|filename| filename.as_ref())
.map(DistFilename::version)
.cloned(),
latest_filetype: latest
.get(dist.name())
.and_then(|filename| filename.as_ref())
.map(FileType::from),
editable_project_location: dist
.as_editable()
.map(|url| url.to_file_path().unwrap().simplified_display().to_string()),
}
})
.collect_vec();
let output = serde_json::to_string(&rows)?;
Expand Down Expand Up @@ -246,6 +268,29 @@ pub(crate) async fn pip_list(
});
}

if true {
columns.push(Column {
header: String::from("Location"),
rows: results
.iter()
.map(|dist| {
if dist.path().parent().is_some() {
dist.path().parent().unwrap().simplified_display().to_string()
} else {
String::new()
}
})
.collect_vec(),
});
columns.push(Column {
header: String::from("Installer"),
rows: results
.iter()
.map(|_| "uv".to_string())
.collect_vec(),
});
}

for elems in MultiZip(columns.iter().map(Column::fmt).collect_vec()) {
println!("{}", elems.join(" ").trim_end());
}
Expand Down Expand Up @@ -326,6 +371,10 @@ struct Entry {
latest_filetype: Option<FileType>,
#[serde(skip_serializing_if = "Option::is_none")]
editable_project_location: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
location: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
installer: Option<String>,
}

/// A column in a table.
Expand Down
39 changes: 39 additions & 0 deletions crates/uv/tests/it/pip_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,42 @@ fn list_ignores_quiet_flag_format_freeze() {
"###
);
}

#[test]
fn list_verbose() -> Result<()> {
let context = TestContext::new("3.12");

let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str("MarkupSafe==2.1.3")?;

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

----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ markupsafe==2.1.3
"###
);

context.assert_command("import markupsafe").success();

uv_snapshot!(context.filters(), context.pip_list()
.arg("--format=json").arg("--verbose"), @r###"
success: true
exit_code: 0
----- stdout -----
[{"name":"markupsafe","version":"2.1.3","location":"[SITE_PACKAGES]","installer":"uv"}]

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

Ok(())
}
Loading