Add `uv workspace list --paths` (#16776)

I initially thought I didn't need this, but in some contexts, the
workspace member name is not useful at all and I just want to iterate
over the paths without composing with `uv workspace dir --package
<name>`
This commit is contained in:
Zanie Blue 2025-11-20 13:44:57 -06:00 committed by GitHub
parent 79bfa2b4cd
commit aebd7578bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 43 additions and 5 deletions

View File

@ -7186,7 +7186,11 @@ pub struct WorkspaceDirArgs {
} }
#[derive(Args, Debug)] #[derive(Args, Debug)]
pub struct WorkspaceListArgs; pub struct WorkspaceListArgs {
/// Show paths instead of names.
#[arg(long)]
pub paths: bool,
}
/// See [PEP 517](https://peps.python.org/pep-0517/) and /// See [PEP 517](https://peps.python.org/pep-0517/) and
/// [PEP 660](https://peps.python.org/pep-0660/) for specifications of the parameters. /// [PEP 660](https://peps.python.org/pep-0660/) for specifications of the parameters.

View File

@ -4,6 +4,7 @@ use std::path::Path;
use anyhow::Result; use anyhow::Result;
use owo_colors::OwoColorize; use owo_colors::OwoColorize;
use uv_fs::Simplified;
use uv_preview::{Preview, PreviewFeatures}; use uv_preview::{Preview, PreviewFeatures};
use uv_warnings::warn_user; use uv_warnings::warn_user;
use uv_workspace::{DiscoveryOptions, Workspace, WorkspaceCache}; use uv_workspace::{DiscoveryOptions, Workspace, WorkspaceCache};
@ -14,6 +15,7 @@ use crate::printer::Printer;
/// List workspace members /// List workspace members
pub(crate) async fn list( pub(crate) async fn list(
project_dir: &Path, project_dir: &Path,
paths: bool,
preview: Preview, preview: Preview,
printer: Printer, printer: Printer,
) -> Result<ExitStatus> { ) -> Result<ExitStatus> {
@ -28,9 +30,17 @@ pub(crate) async fn list(
let workspace = let workspace =
Workspace::discover(project_dir, &DiscoveryOptions::default(), &workspace_cache).await?; Workspace::discover(project_dir, &DiscoveryOptions::default(), &workspace_cache).await?;
for name in workspace.packages().keys() { for (name, member) in workspace.packages() {
if paths {
writeln!(
printer.stdout(),
"{}",
member.root().simplified_display().cyan()
)?;
} else {
writeln!(printer.stdout(), "{}", name.cyan())?; writeln!(printer.stdout(), "{}", name.cyan())?;
} }
}
Ok(ExitStatus::Success) Ok(ExitStatus::Success)
} }

View File

@ -1746,8 +1746,8 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
WorkspaceCommand::Dir(args) => { WorkspaceCommand::Dir(args) => {
commands::dir(args.package, &project_dir, globals.preview, printer).await commands::dir(args.package, &project_dir, globals.preview, printer).await
} }
WorkspaceCommand::List(_args) => { WorkspaceCommand::List(args) => {
commands::list(&project_dir, globals.preview, printer).await commands::list(&project_dir, args.paths, globals.preview, printer).await
} }
}, },
Commands::BuildBackend { command } => spawn_blocking(move || match command { Commands::BuildBackend { command } => spawn_blocking(move || match command {

View File

@ -24,6 +24,17 @@ fn workspace_list_simple() {
warning: The `uv workspace list` command is experimental and may change without warning. Pass `--preview-features workspace-list` to disable this warning. warning: The `uv workspace list` command is experimental and may change without warning. Pass `--preview-features workspace-list` to disable this warning.
" "
); );
uv_snapshot!(context.filters(), context.workspace_list().arg("--paths").current_dir(&workspace), @r"
success: true
exit_code: 0
----- stdout -----
[TEMP_DIR]/foo
----- stderr -----
warning: The `uv workspace list` command is experimental and may change without warning. Pass `--preview-features workspace-list` to disable this warning.
"
);
} }
/// Test list output for a root workspace (workspace with a root package). /// Test list output for a root workspace (workspace with a root package).
@ -152,6 +163,19 @@ fn workspace_list_multiple_members() {
warning: The `uv workspace list` command is experimental and may change without warning. Pass `--preview-features workspace-list` to disable this warning. warning: The `uv workspace list` command is experimental and may change without warning. Pass `--preview-features workspace-list` to disable this warning.
" "
); );
uv_snapshot!(context.filters(), context.workspace_list().arg("--paths").current_dir(&workspace_root), @r"
success: true
exit_code: 0
----- stdout -----
[TEMP_DIR]/pkg-a
[TEMP_DIR]/pkg-a/pkg-b
[TEMP_DIR]/pkg-a/pkg-c
----- stderr -----
warning: The `uv workspace list` command is experimental and may change without warning. Pass `--preview-features workspace-list` to disable this warning.
"
);
} }
/// Test list output for a single project (not a workspace). /// Test list output for a single project (not a workspace).