Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3211,7 +3211,7 @@ pub struct RunArgs {
///
/// uv includes the groups defined in `tool.uv.default-groups` by default.
/// This disables that option, however, specific groups can still be included with `--group`.
#[arg(long)]
#[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS)]
pub no_default_groups: bool,

/// Only include dependencies from the specified dependency group.
Expand Down Expand Up @@ -3540,7 +3540,7 @@ pub struct SyncArgs {
///
/// uv includes the groups defined in `tool.uv.default-groups` by default.
/// This disables that option, however, specific groups can still be included with `--group`.
#[arg(long)]
#[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS)]
pub no_default_groups: bool,

/// Only include dependencies from the specified dependency group.
Expand Down Expand Up @@ -4217,7 +4217,7 @@ pub struct TreeArgs {
///
/// uv includes the groups defined in `tool.uv.default-groups` by default.
/// This disables that option, however, specific groups can still be included with `--group`.
#[arg(long)]
#[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS)]
pub no_default_groups: bool,

/// Only include dependencies from the specified dependency group.
Expand Down Expand Up @@ -4392,7 +4392,7 @@ pub struct ExportArgs {
///
/// uv includes the groups defined in `tool.uv.default-groups` by default.
/// This disables that option, however, specific groups can still be included with `--group`.
#[arg(long)]
#[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS)]
pub no_default_groups: bool,

/// Only include dependencies from the specified dependency group.
Expand Down
5 changes: 5 additions & 0 deletions crates/uv-static/src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ impl EnvVars {
#[attr_added_in("0.9.8")]
pub const UV_NO_GROUP: &'static str = "UV_NO_GROUP";

/// Equivalent to the `--no-default-groups` command-line argument. If set, uv will
/// not select the default dependency groups defined in `tool.uv.default-groups`.
#[attr_added_in("next release")]
pub const UV_NO_DEFAULT_GROUPS: &'static str = "UV_NO_DEFAULT_GROUPS";

/// Equivalent to the `--no-binary` command-line argument. If set, uv will install
/// all packages from source. The resolver will still use pre-built wheels to
/// extract package metadata, if available.
Expand Down
168 changes: 168 additions & 0 deletions crates/uv/tests/it/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4425,6 +4425,174 @@ fn sync_default_groups_gibberish() -> Result<()> {
Ok(())
}

#[test]
fn sync_disable_default_groups_with_environment_variable() -> 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]
dev = ["iniconfig"]
foo = ["anyio"]
bar = ["requests"]

[tool.uv]
default-groups = ["foo"]
"#,
)?;

context.lock().assert().success();

uv_snapshot!(context.filters(), context.sync().arg("--all-groups"), @r"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 10 packages in [TIME]
Prepared 9 packages in [TIME]
Installed 9 packages in [TIME]
+ anyio==4.3.0
+ certifi==2024.2.2
+ charset-normalizer==3.3.2
+ idna==3.6
+ iniconfig==2.0.0
+ requests==2.31.0
+ sniffio==1.3.1
+ typing-extensions==4.10.0
+ urllib3==2.2.1
");

// Using `UV_NO_DEFAULT_GROUPS` should exclude all groups.
uv_snapshot!(context.filters(), context.sync().env(EnvVars::UV_NO_DEFAULT_GROUPS, "true"), @r"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 10 packages in [TIME]
Uninstalled 8 packages in [TIME]
- anyio==4.3.0
- certifi==2024.2.2
- charset-normalizer==3.3.2
- idna==3.6
- iniconfig==2.0.0
- requests==2.31.0
- sniffio==1.3.1
- urllib3==2.2.1
");

uv_snapshot!(context.filters(), context.sync().arg("--all-groups"), @r"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 10 packages in [TIME]
Installed 8 packages in [TIME]
+ anyio==4.3.0
+ certifi==2024.2.2
+ charset-normalizer==3.3.2
+ idna==3.6
+ iniconfig==2.0.0
+ requests==2.31.0
+ sniffio==1.3.1
+ urllib3==2.2.1
");

// Using `UV_NO_DEFAULT_GROUPS` with `--group foo` and `--group bar` should include those groups,
// excluding the remaining `dev` group.
uv_snapshot!(context.filters(), context.sync()
.arg("--group").arg("foo")
.arg("--group").arg("bar")
.env(EnvVars::UV_NO_DEFAULT_GROUPS, "true"), @r"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 10 packages in [TIME]
Uninstalled 1 package in [TIME]
- iniconfig==2.0.0
");

Ok(())
}

#[test]
fn sync_disable_default_groups_all_with_environment_variable() -> Result<()> {
let context = TestContext::new("3.12");

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "myproject"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["typing-extensions"]

[dependency-groups]
dev = ["iniconfig"]
foo = ["anyio"]
bar = ["requests"]

[tool.uv]
default-groups = "all"
"#,
)?;

context.lock().assert().success();

uv_snapshot!(context.filters(), context.sync(), @r"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 10 packages in [TIME]
Prepared 9 packages in [TIME]
Installed 9 packages in [TIME]
+ anyio==4.3.0
+ certifi==2024.2.2
+ charset-normalizer==3.3.2
+ idna==3.6
+ iniconfig==2.0.0
+ requests==2.31.0
+ sniffio==1.3.1
+ typing-extensions==4.10.0
+ urllib3==2.2.1
");

// Using `UV_NO_DEFAULT_GROUPS` should exclude all groups.
uv_snapshot!(context.filters(), context.sync().env(EnvVars::UV_NO_DEFAULT_GROUPS, "true"), @r"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 10 packages in [TIME]
Uninstalled 8 packages in [TIME]
- anyio==4.3.0
- certifi==2024.2.2
- charset-normalizer==3.3.2
- idna==3.6
- iniconfig==2.0.0
- requests==2.31.0
- sniffio==1.3.1
- urllib3==2.2.1
");

Ok(())
}

/// Sync with `--only-group`, where the group includes a workspace member.
#[test]
fn sync_group_member() -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ uv run [OPTIONS] [COMMAND]
<p>Normally, configuration files are discovered in the current directory, parent directories, or user configuration directories.</p>
<p>May also be set with the <code>UV_NO_CONFIG</code> environment variable.</p></dd><dt id="uv-run--no-default-groups"><a href="#uv-run--no-default-groups"><code>--no-default-groups</code></a></dt><dd><p>Ignore the default dependency groups.</p>
<p>uv includes the groups defined in <code>tool.uv.default-groups</code> by default. This disables that option, however, specific groups can still be included with <code>--group</code>.</p>
</dd><dt id="uv-run--no-dev"><a href="#uv-run--no-dev"><code>--no-dev</code></a></dt><dd><p>Disable the development dependency group.</p>
<p>May also be set with the <code>UV_NO_DEFAULT_GROUPS</code> environment variable.</p></dd><dt id="uv-run--no-dev"><a href="#uv-run--no-dev"><code>--no-dev</code></a></dt><dd><p>Disable the development dependency group.</p>
<p>This option is an alias of <code>--no-group dev</code>. See <code>--no-default-groups</code> to disable all default groups instead.</p>
<p>This option is only available when running in a project.</p>
<p>May also be set with the <code>UV_NO_DEV</code> environment variable.</p></dd><dt id="uv-run--no-editable"><a href="#uv-run--no-editable"><code>--no-editable</code></a></dt><dd><p>Install any editable dependencies, including the project and any workspace members, as non-editable</p>
Expand Down Expand Up @@ -1477,7 +1477,7 @@ uv sync [OPTIONS]
<p>Normally, configuration files are discovered in the current directory, parent directories, or user configuration directories.</p>
<p>May also be set with the <code>UV_NO_CONFIG</code> environment variable.</p></dd><dt id="uv-sync--no-default-groups"><a href="#uv-sync--no-default-groups"><code>--no-default-groups</code></a></dt><dd><p>Ignore the default dependency groups.</p>
<p>uv includes the groups defined in <code>tool.uv.default-groups</code> by default. This disables that option, however, specific groups can still be included with <code>--group</code>.</p>
</dd><dt id="uv-sync--no-dev"><a href="#uv-sync--no-dev"><code>--no-dev</code></a></dt><dd><p>Disable the development dependency group.</p>
<p>May also be set with the <code>UV_NO_DEFAULT_GROUPS</code> environment variable.</p></dd><dt id="uv-sync--no-dev"><a href="#uv-sync--no-dev"><code>--no-dev</code></a></dt><dd><p>Disable the development dependency group.</p>
<p>This option is an alias of <code>--no-group dev</code>. See <code>--no-default-groups</code> to disable all default groups instead.</p>
<p>May also be set with the <code>UV_NO_DEV</code> environment variable.</p></dd><dt id="uv-sync--no-editable"><a href="#uv-sync--no-editable"><code>--no-editable</code></a></dt><dd><p>Install any editable dependencies, including the project and any workspace members, as non-editable</p>
<p>May also be set with the <code>UV_NO_EDITABLE</code> environment variable.</p></dd><dt id="uv-sync--no-extra"><a href="#uv-sync--no-extra"><code>--no-extra</code></a> <i>no-extra</i></dt><dd><p>Exclude the specified optional dependencies, if <code>--all-extras</code> is supplied.</p>
Expand Down Expand Up @@ -1910,7 +1910,7 @@ uv export [OPTIONS]
<p>Normally, configuration files are discovered in the current directory, parent directories, or user configuration directories.</p>
<p>May also be set with the <code>UV_NO_CONFIG</code> environment variable.</p></dd><dt id="uv-export--no-default-groups"><a href="#uv-export--no-default-groups"><code>--no-default-groups</code></a></dt><dd><p>Ignore the default dependency groups.</p>
<p>uv includes the groups defined in <code>tool.uv.default-groups</code> by default. This disables that option, however, specific groups can still be included with <code>--group</code>.</p>
</dd><dt id="uv-export--no-dev"><a href="#uv-export--no-dev"><code>--no-dev</code></a></dt><dd><p>Disable the development dependency group.</p>
<p>May also be set with the <code>UV_NO_DEFAULT_GROUPS</code> environment variable.</p></dd><dt id="uv-export--no-dev"><a href="#uv-export--no-dev"><code>--no-dev</code></a></dt><dd><p>Disable the development dependency group.</p>
<p>This option is an alias of <code>--no-group dev</code>. See <code>--no-default-groups</code> to disable all default groups instead.</p>
<p>May also be set with the <code>UV_NO_DEV</code> environment variable.</p></dd><dt id="uv-export--no-editable"><a href="#uv-export--no-editable"><code>--no-editable</code></a></dt><dd><p>Export any editable dependencies, including the project and any workspace members, as non-editable</p>
<p>May also be set with the <code>UV_NO_EDITABLE</code> environment variable.</p></dd><dt id="uv-export--no-emit-local"><a href="#uv-export--no-emit-local"><code>--no-emit-local</code></a>, <code>--no-install-local</code></dt><dd><p>Do not include local path dependencies in the exported requirements.</p>
Expand Down Expand Up @@ -2104,7 +2104,7 @@ uv tree [OPTIONS]
<p>May also be set with the <code>UV_NO_CONFIG</code> environment variable.</p></dd><dt id="uv-tree--no-dedupe"><a href="#uv-tree--no-dedupe"><code>--no-dedupe</code></a></dt><dd><p>Do not de-duplicate repeated dependencies. Usually, when a package has already displayed its dependencies, further occurrences will not re-display its dependencies, and will include a (*) to indicate it has already been shown. This flag will cause those duplicates to be repeated</p>
</dd><dt id="uv-tree--no-default-groups"><a href="#uv-tree--no-default-groups"><code>--no-default-groups</code></a></dt><dd><p>Ignore the default dependency groups.</p>
<p>uv includes the groups defined in <code>tool.uv.default-groups</code> by default. This disables that option, however, specific groups can still be included with <code>--group</code>.</p>
</dd><dt id="uv-tree--no-dev"><a href="#uv-tree--no-dev"><code>--no-dev</code></a></dt><dd><p>Disable the development dependency group.</p>
<p>May also be set with the <code>UV_NO_DEFAULT_GROUPS</code> environment variable.</p></dd><dt id="uv-tree--no-dev"><a href="#uv-tree--no-dev"><code>--no-dev</code></a></dt><dd><p>Disable the development dependency group.</p>
<p>This option is an alias of <code>--no-group dev</code>. See <code>--no-default-groups</code> to disable all default groups instead.</p>
<p>May also be set with the <code>UV_NO_DEV</code> environment variable.</p></dd><dt id="uv-tree--no-group"><a href="#uv-tree--no-group"><code>--no-group</code></a> <i>no-group</i></dt><dd><p>Disable the specified dependency group.</p>
<p>This option always takes precedence over default groups, <code>--all-groups</code>, and <code>--group</code>.</p>
Expand Down
6 changes: 6 additions & 0 deletions docs/reference/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ Equivalent to the `--no-config` command-line argument. If set, uv will not read
any configuration files from the current directory, parent directories, or user configuration
directories.

### `UV_NO_DEFAULT_GROUPS`
<small class="added-in">added in `next release`</small>

Equivalent to the `--no-default-groups` command-line argument. If set, uv will
not select the default dependency groups defined in `tool.uv.default-groups`.

### `UV_NO_DEV`
<small class="added-in">added in `0.8.7`</small>

Expand Down
Loading