From 5819ed4472aef125abe8d70334177983c692e786 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Fri, 18 Oct 2024 13:02:36 -0500 Subject: [PATCH] Add `--group`, `--only-group`, and `--only-dev` support to `uv tree` (#8338) Part of #8090 Most of the heavy lifting is done in #8309 Includes `--only-dev` which appears to be missing as an oversight. --- crates/uv-cli/src/lib.rs | 20 ++++++++++ crates/uv/src/settings.rs | 6 ++- crates/uv/tests/it/tree.rs | 76 ++++++++++++++++++++++++++++++++++++++ docs/reference/cli.md | 14 +++++++ 4 files changed, 114 insertions(+), 2 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 3799193f60e4..14e3c0b1633a 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -3191,10 +3191,30 @@ pub struct TreeArgs { #[arg(long, overrides_with("no_dev"), hide = true)] pub dev: bool, + /// Omit non-development dependencies. + /// + /// The project itself will also be omitted. + #[arg(long, conflicts_with("no_dev"))] + pub only_dev: bool, + /// Omit development dependencies. #[arg(long, overrides_with("dev"), conflicts_with = "invert")] pub no_dev: bool, + /// Include dependencies from the specified local dependency group. + /// + /// May be provided multiple times. + #[arg(long, conflicts_with("only_group"))] + pub group: Vec, + + /// Only include dependencies from the specified local dependency group. + /// + /// May be provided multiple times. + /// + /// The project itself will also be omitted. + #[arg(long, conflicts_with("group"))] + pub only_group: Vec, + /// Assert that the `uv.lock` will remain unchanged. /// /// Requires that the lockfile is up-to-date. If the lockfile is missing or diff --git a/crates/uv/src/settings.rs b/crates/uv/src/settings.rs index 264b79e0ace6..6561dd27f528 100644 --- a/crates/uv/src/settings.rs +++ b/crates/uv/src/settings.rs @@ -1025,7 +1025,10 @@ impl TreeSettings { tree, universal, dev, + only_dev, no_dev, + group, + only_group, locked, frozen, build, @@ -1036,8 +1039,7 @@ impl TreeSettings { } = args; Self { - // TODO(zanieb): Support `--group` here - dev: DevGroupsSpecification::from_args(dev, no_dev, false, vec![], vec![]), + dev: DevGroupsSpecification::from_args(dev, no_dev, only_dev, group, only_group), locked, frozen, universal, diff --git a/crates/uv/tests/it/tree.rs b/crates/uv/tests/it/tree.rs index 25091dff50e1..a03cc2be36d7 100644 --- a/crates/uv/tests/it/tree.rs +++ b/crates/uv/tests/it/tree.rs @@ -1,5 +1,6 @@ use crate::common::{uv_snapshot, TestContext}; use anyhow::Result; +use assert_cmd::assert::OutputAssertExt; use assert_fs::prelude::*; use indoc::formatdoc; use url::Url; @@ -755,3 +756,78 @@ fn package() -> Result<()> { Ok(()) } + +#[test] +fn tree_group() -> Result<()> { + let context = TestContext::new("3.12"); + + let pyproject_toml = context.temp_dir.child("pyproject.toml"); + pyproject_toml.write_str( + r#" + [project] + name = "project" + version = "0.1.0" + requires-python = ">=3.12" + dependencies = ["typing-extensions"] + [dependency-groups] + foo = ["anyio"] + bar = ["iniconfig"] + dev = ["sniffio"] + "#, + )?; + + context.lock().assert().success(); + + uv_snapshot!(context.filters(), context.tree(), @r###" + success: true + exit_code: 0 + ----- stdout ----- + project v0.1.0 + ├── typing-extensions v4.10.0 + └── sniffio v1.3.1 (group: dev) + + ----- stderr ----- + Resolved 6 packages in [TIME] + "###); + + uv_snapshot!(context.filters(), context.tree().arg("--only-group").arg("bar"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + project v0.1.0 + └── iniconfig v2.0.0 (group: bar) + ----- stderr ----- + Resolved 6 packages in [TIME] + "###); + + uv_snapshot!(context.filters(), context.tree().arg("--group").arg("foo"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + project v0.1.0 + ├── typing-extensions v4.10.0 + ├── sniffio v1.3.1 (group: dev) + └── anyio v4.3.0 (group: foo) + ├── idna v3.6 + └── sniffio v1.3.1 + ----- stderr ----- + Resolved 6 packages in [TIME] + "###); + + uv_snapshot!(context.filters(), context.tree().arg("--group").arg("foo").arg("--group").arg("bar"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + project v0.1.0 + ├── typing-extensions v4.10.0 + ├── iniconfig v2.0.0 (group: bar) + ├── sniffio v1.3.1 (group: dev) + └── anyio v4.3.0 (group: foo) + ├── idna v3.6 + └── sniffio v1.3.1 + ----- stderr ----- + Resolved 6 packages in [TIME] + "###); + + Ok(()) +} diff --git a/docs/reference/cli.md b/docs/reference/cli.md index ee1c3a4ec554..f29b4af9c0a3 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -2393,6 +2393,10 @@ uv tree [OPTIONS]

If the lockfile is missing, uv will exit with an error.

May also be set with the UV_FROZEN environment variable.

+
--group group

Include dependencies from the specified local dependency group.

+ +

May be provided multiple times.

+
--help, -h

Display the concise help for this command

--index index

The URLs to use when resolving dependencies, in addition to the default index.

@@ -2516,6 +2520,16 @@ uv tree [OPTIONS]

When disabled, uv will only use locally cached data and locally available files.

+
--only-dev

Omit non-development dependencies.

+ +

The project itself will also be omitted.

+ +
--only-group only-group

Only include dependencies from the specified local dependency group.

+ +

May be provided multiple times.

+ +

The project itself will also be omitted.

+
--package package

Display only the specified packages

--prerelease prerelease

The strategy to use when considering pre-release versions.