-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add uv tool list
#4630
Merged
+168
−3
Merged
Add uv tool list
#4630
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::fmt::Write; | ||
|
||
use anyhow::Result; | ||
|
||
use uv_configuration::PreviewMode; | ||
use uv_tool::InstalledTools; | ||
use uv_warnings::warn_user_once; | ||
|
||
use crate::commands::ExitStatus; | ||
use crate::printer::Printer; | ||
|
||
/// List installed tools. | ||
#[allow(clippy::too_many_arguments)] | ||
pub(crate) async fn list(preview: PreviewMode, printer: Printer) -> Result<ExitStatus> { | ||
if preview.is_disabled() { | ||
warn_user_once!("`uv tool list` is experimental and may change without warning."); | ||
} | ||
|
||
let installed_tools = InstalledTools::from_settings()?; | ||
|
||
let mut tools = installed_tools.tools()?.into_iter().collect::<Vec<_>>(); | ||
tools.sort_by_key(|(name, _)| name.clone()); | ||
|
||
if tools.is_empty() { | ||
writeln!(printer.stderr(), "No tools installed")?; | ||
return Ok(ExitStatus::Success); | ||
} | ||
|
||
// TODO(zanieb): Track and display additional metadata, like entry points | ||
for (name, _tool) in tools { | ||
writeln!(printer.stdout(), "{name}")?; | ||
} | ||
|
||
Ok(ExitStatus::Success) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub(crate) mod install; | ||
pub(crate) mod list; | ||
pub(crate) mod run; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#![cfg(all(feature = "python", feature = "pypi"))] | ||
|
||
use assert_cmd::assert::OutputAssertExt; | ||
use assert_fs::fixture::PathChild; | ||
use common::{uv_snapshot, TestContext}; | ||
|
||
mod common; | ||
|
||
#[test] | ||
fn tool_list() { | ||
let context = TestContext::new("3.12"); | ||
let tool_dir = context.temp_dir.child("tools"); | ||
let bin_dir = context.temp_dir.child("bin"); | ||
|
||
// Install `black` | ||
context | ||
.tool_install() | ||
.arg("black==24.2.0") | ||
.env("UV_TOOL_DIR", tool_dir.as_os_str()) | ||
.env("XDG_BIN_HOME", bin_dir.as_os_str()) | ||
.assert() | ||
.success(); | ||
|
||
uv_snapshot!(context.filters(), context.tool_list() | ||
.env("UV_TOOL_DIR", tool_dir.as_os_str()) | ||
.env("XDG_BIN_HOME", bin_dir.as_os_str()), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
black | ||
|
||
----- stderr ----- | ||
warning: `uv tool list` is experimental and may change without warning. | ||
"###); | ||
} | ||
|
||
#[test] | ||
fn tool_list_empty() { | ||
let context = TestContext::new("3.12"); | ||
let tool_dir = context.temp_dir.child("tools"); | ||
let bin_dir = context.temp_dir.child("bin"); | ||
|
||
uv_snapshot!(context.filters(), context.tool_list() | ||
.env("UV_TOOL_DIR", tool_dir.as_os_str()) | ||
.env("XDG_BIN_HOME", bin_dir.as_os_str()), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
warning: `uv tool list` is experimental and may change without warning. | ||
No tools installed | ||
"###); | ||
} | ||
|
||
#[test] | ||
fn tool_list_missing_receipt() { | ||
let context = TestContext::new("3.12"); | ||
let tool_dir = context.temp_dir.child("tools"); | ||
let bin_dir = context.temp_dir.child("bin"); | ||
|
||
// Install `black` | ||
context | ||
.tool_install() | ||
.arg("black==24.2.0") | ||
.env("UV_TOOL_DIR", tool_dir.as_os_str()) | ||
.env("XDG_BIN_HOME", bin_dir.as_os_str()) | ||
.assert() | ||
.success(); | ||
|
||
fs_err::remove_file(tool_dir.join("black").join("uv-receipt.toml")).unwrap(); | ||
|
||
uv_snapshot!(context.filters(), context.tool_list() | ||
.env("UV_TOOL_DIR", tool_dir.as_os_str()) | ||
.env("XDG_BIN_HOME", bin_dir.as_os_str()), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
warning: `uv tool list` is experimental and may change without warning. | ||
warning: Ignoring malformed tool `black`: missing receipt | ||
No tools installed | ||
"###); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we include the version, like
pip list
?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.
That seems nice!
I'll probably do in a follow-up to separate it from all this boilerplate.