Skip to content

Commit

Permalink
Remove dev dependencies in --all-groups --no-dev (#9300)
Browse files Browse the repository at this point in the history
## Summary

Closes #9297.
  • Loading branch information
charliermarsh authored Nov 21, 2024
1 parent 98c96b7 commit c6482dd
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 16 deletions.
31 changes: 26 additions & 5 deletions crates/uv-configuration/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,32 @@ impl DevGroupsSpecification {

/// Returns `true` if the group is included in the specification.
pub fn contains(&self, group: &GroupName) -> bool {
self.dev.as_ref().map_or(false, |dev| dev.contains(group))
|| self
.groups
.as_ref()
.map_or(false, |groups| groups.contains(group))
if group == &*DEV_DEPENDENCIES {
match self.dev.as_ref() {
None => {}
Some(DevMode::Exclude) => {
// If `--no-dev` was provided, always exclude dev.
return false;
}
Some(DevMode::Only) => {
// If `--only-dev` was provided, always include dev.
return true;
}
Some(DevMode::Include) => {
// If `--no-group dev` was provided, exclude dev.
return match self.groups.as_ref() {
Some(GroupsSpecification::Include { exclude, .. }) => {
!exclude.contains(group)
}
_ => true,
};
}
}
}

self.groups
.as_ref()
.map_or(false, |groups| groups.contains(group))
}
}

Expand Down
84 changes: 73 additions & 11 deletions crates/uv/tests/it/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,10 @@ fn sync_group() -> Result<()> {
requires-python = ">=3.12"
dependencies = ["typing-extensions"]
[tool.uv]
[dependency-groups]
dev = ["iniconfig"]
foo = ["anyio"]
bar = ["requests"]
"#,
Expand All @@ -1226,9 +1229,10 @@ fn sync_group() -> Result<()> {
----- stdout -----
----- stderr -----
Resolved 9 packages in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
Resolved 10 packages in [TIME]
Prepared 2 packages in [TIME]
Installed 2 packages in [TIME]
+ iniconfig==2.0.0
+ typing-extensions==4.10.0
"###);

Expand All @@ -1238,7 +1242,7 @@ fn sync_group() -> Result<()> {
----- stdout -----
----- stderr -----
Resolved 9 packages in [TIME]
Resolved 10 packages in [TIME]
Prepared 3 packages in [TIME]
Installed 3 packages in [TIME]
+ anyio==4.3.0
Expand All @@ -1252,13 +1256,14 @@ fn sync_group() -> Result<()> {
----- stdout -----
----- stderr -----
Resolved 9 packages in [TIME]
Resolved 10 packages in [TIME]
Prepared 4 packages in [TIME]
Uninstalled 3 packages in [TIME]
Uninstalled 4 packages in [TIME]
Installed 4 packages in [TIME]
- anyio==4.3.0
+ certifi==2024.2.2
+ charset-normalizer==3.3.2
- iniconfig==2.0.0
+ requests==2.31.0
- sniffio==1.3.1
- typing-extensions==4.10.0
Expand All @@ -1271,9 +1276,10 @@ fn sync_group() -> Result<()> {
----- stdout -----
----- stderr -----
Resolved 9 packages in [TIME]
Installed 3 packages in [TIME]
Resolved 10 packages in [TIME]
Installed 4 packages in [TIME]
+ anyio==4.3.0
+ iniconfig==2.0.0
+ sniffio==1.3.1
+ typing-extensions==4.10.0
"###);
Expand All @@ -1284,8 +1290,8 @@ fn sync_group() -> Result<()> {
----- stdout -----
----- stderr -----
Resolved 9 packages in [TIME]
Audited 8 packages in [TIME]
Resolved 10 packages in [TIME]
Audited 9 packages in [TIME]
"###);

uv_snapshot!(context.filters(), context.sync().arg("--all-groups").arg("--no-group").arg("bar"), @r###"
Expand All @@ -1294,14 +1300,70 @@ fn sync_group() -> Result<()> {
----- stdout -----
----- stderr -----
Resolved 9 packages in [TIME]
Resolved 10 packages in [TIME]
Uninstalled 4 packages in [TIME]
- certifi==2024.2.2
- charset-normalizer==3.3.2
- requests==2.31.0
- urllib3==2.2.1
"###);

uv_snapshot!(context.filters(), context.sync().arg("--all-groups").arg("--no-dev"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 10 packages in [TIME]
Uninstalled 1 package in [TIME]
Installed 4 packages in [TIME]
+ certifi==2024.2.2
+ charset-normalizer==3.3.2
- iniconfig==2.0.0
+ requests==2.31.0
+ urllib3==2.2.1
"###);

uv_snapshot!(context.filters(), context.sync().arg("--dev"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 10 packages in [TIME]
Uninstalled 7 packages in [TIME]
Installed 1 package 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("--dev").arg("--no-group").arg("dev"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 10 packages in [TIME]
Uninstalled 1 package in [TIME]
- iniconfig==2.0.0
"###);

uv_snapshot!(context.filters(), context.sync().arg("--group").arg("dev").arg("--no-dev"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 10 packages in [TIME]
Audited 1 package in [TIME]
"###);

Ok(())
}

Expand Down

0 comments on commit c6482dd

Please sign in to comment.