This commit is contained in:
Julien 2025-06-29 23:55:47 +02:00 committed by GitHub
commit 8ba683237f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 110 additions and 15 deletions

View file

@ -159,26 +159,54 @@ pub(crate) async fn pip_list(
results
};
let verbose = true; // TODO: this should be a flag
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() {
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)?;
@ -255,6 +283,30 @@ 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());
}
@ -335,6 +387,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.

View file

@ -788,3 +788,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(())
}