-
Notifications
You must be signed in to change notification settings - Fork 900
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,26 +150,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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pip lists the location where the package is installed, for example The |
||
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)?; | ||
|
@@ -246,6 +274,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()); | ||
} | ||
|
@@ -326,6 +378,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. | ||
|
There was a problem hiding this comment.
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?