Skip to content

Commit

Permalink
Add --group, --only-group, and --only-dev support to uv tree (#…
Browse files Browse the repository at this point in the history
…8338)

Part of #8090

Most of the heavy lifting is done in #8309

Includes `--only-dev` which appears to be missing as an oversight.
  • Loading branch information
zanieb authored and charliermarsh committed Oct 25, 2024
1 parent dc237d9 commit 5819ed4
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
20 changes: 20 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupName>,

/// 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<GroupName>,

/// Assert that the `uv.lock` will remain unchanged.
///
/// Requires that the lockfile is up-to-date. If the lockfile is missing or
Expand Down
6 changes: 4 additions & 2 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,10 @@ impl TreeSettings {
tree,
universal,
dev,
only_dev,
no_dev,
group,
only_group,
locked,
frozen,
build,
Expand All @@ -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,
Expand Down
76 changes: 76 additions & 0 deletions crates/uv/tests/it/tree.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(())
}
14 changes: 14 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2393,6 +2393,10 @@ uv tree [OPTIONS]
<p>If the lockfile is missing, uv will exit with an error.</p>

<p>May also be set with the <code>UV_FROZEN</code> environment variable.</p>
</dd><dt><code>--group</code> <i>group</i></dt><dd><p>Include dependencies from the specified local dependency group.</p>

<p>May be provided multiple times.</p>

</dd><dt><code>--help</code>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>

</dd><dt><code>--index</code> <i>index</i></dt><dd><p>The URLs to use when resolving dependencies, in addition to the default index.</p>
Expand Down Expand Up @@ -2516,6 +2520,16 @@ uv tree [OPTIONS]

<p>When disabled, uv will only use locally cached data and locally available files.</p>

</dd><dt><code>--only-dev</code></dt><dd><p>Omit non-development dependencies.</p>

<p>The project itself will also be omitted.</p>

</dd><dt><code>--only-group</code> <i>only-group</i></dt><dd><p>Only include dependencies from the specified local dependency group.</p>

<p>May be provided multiple times.</p>

<p>The project itself will also be omitted.</p>

</dd><dt><code>--package</code> <i>package</i></dt><dd><p>Display only the specified packages</p>

</dd><dt><code>--prerelease</code> <i>prerelease</i></dt><dd><p>The strategy to use when considering pre-release versions.</p>
Expand Down

0 comments on commit 5819ed4

Please sign in to comment.