Skip to content

Commit 1479f52

Browse files
feat: add --no-default-groups flag (#10618)
## Summary Closes #10592. ## Test Plan Snapshot tests. --------- Co-authored-by: Charlie Marsh <[email protected]>
1 parent cee8770 commit 1479f52

File tree

5 files changed

+297
-9
lines changed

5 files changed

+297
-9
lines changed

crates/uv-cli/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,6 +2716,12 @@ pub struct RunArgs {
27162716
#[arg(long)]
27172717
pub no_group: Vec<GroupName>,
27182718

2719+
/// Exclude dependencies from default groups.
2720+
///
2721+
/// `--group` can be used to include specific groups.
2722+
#[arg(long, conflicts_with_all = ["no_group", "only_group"])]
2723+
pub no_default_groups: bool,
2724+
27192725
/// Only include dependencies from the specified dependency group.
27202726
///
27212727
/// May be provided multiple times.
@@ -2981,6 +2987,12 @@ pub struct SyncArgs {
29812987
#[arg(long)]
29822988
pub no_group: Vec<GroupName>,
29832989

2990+
/// Exclude dependencies from default groups.
2991+
///
2992+
/// `--group` can be used to include specific groups.
2993+
#[arg(long, conflicts_with_all = ["no_group", "only_group"])]
2994+
pub no_default_groups: bool,
2995+
29842996
/// Only include dependencies from the specified dependency group.
29852997
///
29862998
/// May be provided multiple times.
@@ -3426,6 +3438,12 @@ pub struct TreeArgs {
34263438
#[arg(long)]
34273439
pub no_group: Vec<GroupName>,
34283440

3441+
/// Exclude dependencies from default groups.
3442+
///
3443+
/// `--group` can be used to include specific groups.
3444+
#[arg(long, conflicts_with_all = ["no_group", "only_group"])]
3445+
pub no_default_groups: bool,
3446+
34293447
/// Only include dependencies from the specified dependency group.
34303448
///
34313449
/// May be provided multiple times.
@@ -3590,6 +3608,12 @@ pub struct ExportArgs {
35903608
#[arg(long)]
35913609
pub no_group: Vec<GroupName>,
35923610

3611+
/// Exclude dependencies from default groups.
3612+
///
3613+
/// `--group` can be used to include specific groups.
3614+
#[arg(long, conflicts_with_all = ["no_group", "only_group"])]
3615+
pub no_default_groups: bool,
3616+
35933617
/// Only include dependencies from the specified dependency group.
35943618
///
35953619
/// May be provided multiple times.

crates/uv-configuration/src/dev.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::borrow::Cow;
22

3+
use either::Either;
4+
35
use uv_normalize::{GroupName, DEV_DEPENDENCIES};
46

57
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
@@ -57,14 +59,19 @@ pub struct DevGroupsSpecification {
5759

5860
#[derive(Debug, Clone)]
5961
pub enum GroupsSpecification {
60-
/// Include dependencies from the specified groups.
62+
/// Include dependencies from the specified groups alongside the default groups (omitting
63+
/// those default groups that are explicitly excluded).
6164
///
6265
/// If the `include` is `IncludeGroups::Some`, it is guaranteed to omit groups in the `exclude`
6366
/// list (i.e., they have an empty intersection).
6467
Include {
6568
include: IncludeGroups,
6669
exclude: Vec<GroupName>,
6770
},
71+
/// Include dependencies from the specified groups, omitting any default groups.
72+
///
73+
/// If the list is empty, no group will be included.
74+
Explicit { include: Vec<GroupName> },
6875
/// Only include dependencies from the specified groups, exclude all other dependencies.
6976
///
7077
/// The `include` list is guaranteed to omit groups in the `exclude` list (i.e., they have an
@@ -86,7 +93,7 @@ impl GroupsSpecification {
8693

8794
/// Returns `true` if the specification allows for production dependencies.
8895
pub fn prod(&self) -> bool {
89-
matches!(self, Self::Include { .. })
96+
matches!(self, Self::Include { .. } | Self::Explicit { .. })
9097
}
9198

9299
/// Returns `true` if the specification is limited to a select set of groups.
@@ -118,16 +125,24 @@ impl GroupsSpecification {
118125
[group] => Some(Cow::Owned(format!("--only-group {group}"))),
119126
[..] => Some(Cow::Borrowed("--only-group")),
120127
},
128+
Self::Explicit { include } => match include.as_slice() {
129+
[] => Some(Cow::Borrowed("--no-default-groups")),
130+
[group] => Some(Cow::Owned(format!("--group {group}"))),
131+
[..] => Some(Cow::Borrowed("--group")),
132+
},
121133
}
122134
}
123135

124136
/// Iterate over all groups referenced in the [`DevGroupsSpecification`].
125137
pub fn names(&self) -> impl Iterator<Item = &GroupName> {
126138
match self {
127139
GroupsSpecification::Include { include, exclude } => {
128-
include.names().chain(exclude.iter())
140+
Either::Left(include.names().chain(exclude.iter()))
141+
}
142+
GroupsSpecification::Only { include, exclude } => {
143+
Either::Left(include.iter().chain(exclude.iter()))
129144
}
130-
GroupsSpecification::Only { include, exclude } => include.iter().chain(exclude.iter()),
145+
GroupsSpecification::Explicit { include } => Either::Right(include.iter()),
131146
}
132147
}
133148

@@ -139,6 +154,7 @@ impl GroupsSpecification {
139154
include.contains(group) && !exclude.contains(group)
140155
}
141156
GroupsSpecification::Only { include, .. } => include.contains(group),
157+
GroupsSpecification::Explicit { include } => include.contains(group),
142158
}
143159
}
144160
}
@@ -178,6 +194,7 @@ impl DevGroupsSpecification {
178194
only_dev: bool,
179195
mut group: Vec<GroupName>,
180196
no_group: Vec<GroupName>,
197+
no_default_groups: bool,
181198
mut only_group: Vec<GroupName>,
182199
all_groups: bool,
183200
) -> Self {
@@ -191,7 +208,12 @@ impl DevGroupsSpecification {
191208
None
192209
};
193210

194-
let groups = if all_groups {
211+
let groups = if no_default_groups {
212+
// Remove groups specified with `--no-group`.
213+
group.retain(|group| !no_group.contains(group));
214+
215+
Some(GroupsSpecification::Explicit { include: group })
216+
} else if all_groups {
195217
Some(GroupsSpecification::Include {
196218
include: IncludeGroups::All,
197219
exclude: no_group,
@@ -376,6 +398,12 @@ impl DevGroupsManifest {
376398
};
377399
}
378400

401+
// If `--no-default-groups` was provided, only include group if it's explicitly
402+
// included with `--group <group>`.
403+
if let Some(GroupsSpecification::Explicit { include }) = self.spec.groups() {
404+
return include.contains(group);
405+
}
406+
379407
// If `--no-group` was provided, exclude the group from the list of defaults.
380408
if let Some(GroupsSpecification::Include {
381409
include: _,

crates/uv/src/settings.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ impl RunSettings {
300300
no_dev,
301301
group,
302302
no_group,
303+
no_default_groups,
303304
only_group,
304305
all_groups,
305306
module: _,
@@ -343,7 +344,14 @@ impl RunSettings {
343344
extra.unwrap_or_default(),
344345
),
345346
dev: DevGroupsSpecification::from_args(
346-
dev, no_dev, only_dev, group, no_group, only_group, all_groups,
347+
dev,
348+
no_dev,
349+
only_dev,
350+
group,
351+
no_group,
352+
no_default_groups,
353+
only_group,
354+
all_groups,
347355
),
348356
editable: EditableMode::from_args(no_editable),
349357
modifications: if flag(exact, inexact).unwrap_or(false) {
@@ -960,6 +968,7 @@ impl SyncSettings {
960968
only_dev,
961969
group,
962970
no_group,
971+
no_default_groups,
963972
only_group,
964973
all_groups,
965974
no_editable,
@@ -996,7 +1005,14 @@ impl SyncSettings {
9961005
extra.unwrap_or_default(),
9971006
),
9981007
dev: DevGroupsSpecification::from_args(
999-
dev, no_dev, only_dev, group, no_group, only_group, all_groups,
1008+
dev,
1009+
no_dev,
1010+
only_dev,
1011+
group,
1012+
no_group,
1013+
no_default_groups,
1014+
only_group,
1015+
all_groups,
10001016
),
10011017
editable: EditableMode::from_args(no_editable),
10021018
install_options: InstallOptions::new(
@@ -1316,6 +1332,7 @@ impl TreeSettings {
13161332
no_dev,
13171333
group,
13181334
no_group,
1335+
no_default_groups,
13191336
only_group,
13201337
all_groups,
13211338
locked,
@@ -1334,7 +1351,14 @@ impl TreeSettings {
13341351

13351352
Self {
13361353
dev: DevGroupsSpecification::from_args(
1337-
dev, no_dev, only_dev, group, no_group, only_group, all_groups,
1354+
dev,
1355+
no_dev,
1356+
only_dev,
1357+
group,
1358+
no_group,
1359+
no_default_groups,
1360+
only_group,
1361+
all_groups,
13381362
),
13391363
locked,
13401364
frozen,
@@ -1397,6 +1421,7 @@ impl ExportSettings {
13971421
only_dev,
13981422
group,
13991423
no_group,
1424+
no_default_groups,
14001425
only_group,
14011426
all_groups,
14021427
header,
@@ -1432,7 +1457,14 @@ impl ExportSettings {
14321457
extra.unwrap_or_default(),
14331458
),
14341459
dev: DevGroupsSpecification::from_args(
1435-
dev, no_dev, only_dev, group, no_group, only_group, all_groups,
1460+
dev,
1461+
no_dev,
1462+
only_dev,
1463+
group,
1464+
no_group,
1465+
no_default_groups,
1466+
only_group,
1467+
all_groups,
14361468
),
14371469
editable: EditableMode::from_args(no_editable),
14381470
hashes: flag(hashes, no_hashes).unwrap_or(true),

0 commit comments

Comments
 (0)