Skip to content

Commit a1f9f28

Browse files
authored
Do not allow uv add --group ... --script (#13997)
## Summary Closes #13988 ## Test Plan `cargo test`
1 parent 806cc5c commit a1f9f28

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

crates/uv-cli/src/lib.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3516,7 +3516,12 @@ pub struct AddArgs {
35163516
/// Add the requirements to the development dependency group.
35173517
///
35183518
/// This option is an alias for `--group dev`.
3519-
#[arg(long, conflicts_with("optional"), conflicts_with("group"))]
3519+
#[arg(
3520+
long,
3521+
conflicts_with("optional"),
3522+
conflicts_with("group"),
3523+
conflicts_with("script")
3524+
)]
35203525
pub dev: bool,
35213526

35223527
/// Add the requirements to the package's optional dependencies for the specified extra.
@@ -3530,7 +3535,12 @@ pub struct AddArgs {
35303535
/// Add the requirements to the specified dependency group.
35313536
///
35323537
/// These requirements will not be included in the published metadata for the project.
3533-
#[arg(long, conflicts_with("dev"), conflicts_with("optional"))]
3538+
#[arg(
3539+
long,
3540+
conflicts_with("dev"),
3541+
conflicts_with("optional"),
3542+
conflicts_with("script")
3543+
)]
35343544
pub group: Option<GroupName>,
35353545

35363546
/// Add the requirements as editable.
@@ -3677,11 +3687,21 @@ pub struct RemoveArgs {
36773687
pub dev: bool,
36783688

36793689
/// Remove the packages from the project's optional dependencies for the specified extra.
3680-
#[arg(long, conflicts_with("dev"), conflicts_with("group"))]
3690+
#[arg(
3691+
long,
3692+
conflicts_with("dev"),
3693+
conflicts_with("group"),
3694+
conflicts_with("script")
3695+
)]
36813696
pub optional: Option<ExtraName>,
36823697

36833698
/// Remove the packages from the specified dependency group.
3684-
#[arg(long, conflicts_with("dev"), conflicts_with("optional"))]
3699+
#[arg(
3700+
long,
3701+
conflicts_with("dev"),
3702+
conflicts_with("optional"),
3703+
conflicts_with("script")
3704+
)]
36853705
pub group: Option<GroupName>,
36863706

36873707
/// Avoid syncing the virtual environment after re-locking the project.

crates/uv/tests/it/edit.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,42 @@ fn remove_both_dev() -> Result<()> {
20132013
Ok(())
20142014
}
20152015

2016+
/// Do not allow add for groups in scripts.
2017+
#[test]
2018+
fn disallow_group_script_add() -> Result<()> {
2019+
let context = TestContext::new("3.12");
2020+
2021+
let script = context.temp_dir.child("main.py");
2022+
script.write_str(indoc! {r#"
2023+
# /// script
2024+
# requires-python = ">=3.13"
2025+
# dependencies = []
2026+
#
2027+
# ///
2028+
"#})?;
2029+
2030+
uv_snapshot!(context.filters(), context
2031+
.add()
2032+
.arg("--group")
2033+
.arg("dev")
2034+
.arg("anyio==3.7.0")
2035+
.arg("--script")
2036+
.arg("main.py"), @r###"
2037+
success: false
2038+
exit_code: 2
2039+
----- stdout -----
2040+
2041+
----- stderr -----
2042+
error: the argument '--group <GROUP>' cannot be used with '--script <SCRIPT>'
2043+
2044+
Usage: uv add --cache-dir [CACHE_DIR] --group <GROUP> --exclude-newer <EXCLUDE_NEWER> <PACKAGES|--requirements <REQUIREMENTS>>
2045+
2046+
For more information, try '--help'.
2047+
"###);
2048+
2049+
Ok(())
2050+
}
2051+
20162052
/// `uv remove --group dev` should remove from both `dev-dependencies` and `dependency-groups.dev`.
20172053
#[test]
20182054
fn remove_both_dev_group() -> Result<()> {

0 commit comments

Comments
 (0)