diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 5a3946b936115..d1a9475f274a5 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/crates/uv-static/src/env_vars.rs b/crates/uv-static/src/env_vars.rs index c0ddd6f20ae4b..fa2640c22cf7b 100644 --- a/crates/uv-static/src/env_vars.rs +++ b/crates/uv-static/src/env_vars.rs @@ -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. diff --git a/crates/uv/tests/it/sync.rs b/crates/uv/tests/it/sync.rs index 46095a838a354..7765b1b257aeb 100644 --- a/crates/uv/tests/it/sync.rs +++ b/crates/uv/tests/it/sync.rs @@ -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<()> { diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 11ef15ebeae7f..a99926388f6b5 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -485,7 +485,7 @@ uv run [OPTIONS] [COMMAND]
Normally, configuration files are discovered in the current directory, parent directories, or user configuration directories.
May also be set with the UV_NO_CONFIG environment variable.
--no-default-groupsIgnore the default dependency groups.
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.
--no-devDisable the development dependency group.
+May also be set with the UV_NO_DEFAULT_GROUPS environment variable.
--no-devDisable the development dependency group.
This option is an alias of --no-group dev. See --no-default-groups to disable all default groups instead.
This option is only available when running in a project.
May also be set with the UV_NO_DEV environment variable.
--no-editableInstall any editable dependencies, including the project and any workspace members, as non-editable
@@ -1477,7 +1477,7 @@ uv sync [OPTIONS]Normally, configuration files are discovered in the current directory, parent directories, or user configuration directories.
May also be set with the UV_NO_CONFIG environment variable.
--no-default-groupsIgnore the default dependency groups.
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.
--no-devDisable the development dependency group.
+May also be set with the UV_NO_DEFAULT_GROUPS environment variable.
--no-devDisable the development dependency group.
This option is an alias of --no-group dev. See --no-default-groups to disable all default groups instead.
May also be set with the UV_NO_DEV environment variable.
--no-editableInstall any editable dependencies, including the project and any workspace members, as non-editable
May also be set with the UV_NO_EDITABLE environment variable.
--no-extra no-extraExclude the specified optional dependencies, if --all-extras is supplied.
Normally, configuration files are discovered in the current directory, parent directories, or user configuration directories.
May also be set with the UV_NO_CONFIG environment variable.
--no-default-groupsIgnore the default dependency groups.
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.
--no-devDisable the development dependency group.
+May also be set with the UV_NO_DEFAULT_GROUPS environment variable.
--no-devDisable the development dependency group.
This option is an alias of --no-group dev. See --no-default-groups to disable all default groups instead.
May also be set with the UV_NO_DEV environment variable.
--no-editableExport any editable dependencies, including the project and any workspace members, as non-editable
May also be set with the UV_NO_EDITABLE environment variable.
--no-emit-local, --no-install-localDo not include local path dependencies in the exported requirements.
@@ -2104,7 +2104,7 @@ uv tree [OPTIONS]May also be set with the UV_NO_CONFIG environment variable.
--no-dedupeDo 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
--no-default-groupsIgnore the default dependency groups.
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.
--no-devDisable the development dependency group.
+May also be set with the UV_NO_DEFAULT_GROUPS environment variable.
--no-devDisable the development dependency group.
This option is an alias of --no-group dev. See --no-default-groups to disable all default groups instead.
May also be set with the UV_NO_DEV environment variable.
--no-group no-groupDisable the specified dependency group.
This option always takes precedence over default groups, --all-groups, and --group.