Skip to content

feat: add --no-default-groups flag #10618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 21, 2025
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
24 changes: 24 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,12 @@ pub struct RunArgs {
#[arg(long)]
pub no_group: Vec<GroupName>,

/// Exclude dependencies from default groups.
///
/// `--group` can be used to include specific groups.
#[arg(long, conflicts_with_all = ["no_group", "only_group"])]
pub no_default_groups: bool,

/// Only include dependencies from the specified dependency group.
///
/// May be provided multiple times.
Expand Down Expand Up @@ -2981,6 +2987,12 @@ pub struct SyncArgs {
#[arg(long)]
pub no_group: Vec<GroupName>,

/// Exclude dependencies from default groups.
///
/// `--group` can be used to include specific groups.
#[arg(long, conflicts_with_all = ["no_group", "only_group"])]
pub no_default_groups: bool,

/// Only include dependencies from the specified dependency group.
///
/// May be provided multiple times.
Expand Down Expand Up @@ -3426,6 +3438,12 @@ pub struct TreeArgs {
#[arg(long)]
pub no_group: Vec<GroupName>,

/// Exclude dependencies from default groups.
///
/// `--group` can be used to include specific groups.
#[arg(long, conflicts_with_all = ["no_group", "only_group"])]
pub no_default_groups: bool,

/// Only include dependencies from the specified dependency group.
///
/// May be provided multiple times.
Expand Down Expand Up @@ -3590,6 +3608,12 @@ pub struct ExportArgs {
#[arg(long)]
pub no_group: Vec<GroupName>,

/// Exclude dependencies from default groups.
///
/// `--group` can be used to include specific groups.
#[arg(long, conflicts_with_all = ["no_group", "only_group"])]
pub no_default_groups: bool,

/// Only include dependencies from the specified dependency group.
///
/// May be provided multiple times.
Expand Down
38 changes: 33 additions & 5 deletions crates/uv-configuration/src/dev.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::borrow::Cow;

use either::Either;

use uv_normalize::{GroupName, DEV_DEPENDENCIES};

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

#[derive(Debug, Clone)]
pub enum GroupsSpecification {
/// Include dependencies from the specified groups.
/// Include dependencies from the specified groups alongside the default groups (omitting
/// those default groups that are explicitly excluded).
///
/// If the `include` is `IncludeGroups::Some`, it is guaranteed to omit groups in the `exclude`
/// list (i.e., they have an empty intersection).
Include {
include: IncludeGroups,
exclude: Vec<GroupName>,
},
/// Include dependencies from the specified groups, omitting any default groups.
///
/// If the list is empty, no group will be included.
Explicit { include: Vec<GroupName> },
/// Only include dependencies from the specified groups, exclude all other dependencies.
///
/// The `include` list is guaranteed to omit groups in the `exclude` list (i.e., they have an
Expand All @@ -86,7 +93,7 @@ impl GroupsSpecification {

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

/// Returns `true` if the specification is limited to a select set of groups.
Expand Down Expand Up @@ -118,16 +125,24 @@ impl GroupsSpecification {
[group] => Some(Cow::Owned(format!("--only-group {group}"))),
[..] => Some(Cow::Borrowed("--only-group")),
},
Self::Explicit { include } => match include.as_slice() {
[] => Some(Cow::Borrowed("--no-default-groups")),
[group] => Some(Cow::Owned(format!("--group {group}"))),
[..] => Some(Cow::Borrowed("--group")),
},
}
}

/// Iterate over all groups referenced in the [`DevGroupsSpecification`].
pub fn names(&self) -> impl Iterator<Item = &GroupName> {
match self {
GroupsSpecification::Include { include, exclude } => {
include.names().chain(exclude.iter())
Either::Left(include.names().chain(exclude.iter()))
}
GroupsSpecification::Only { include, exclude } => {
Either::Left(include.iter().chain(exclude.iter()))
}
GroupsSpecification::Only { include, exclude } => include.iter().chain(exclude.iter()),
GroupsSpecification::Explicit { include } => Either::Right(include.iter()),
}
}

Expand All @@ -139,6 +154,7 @@ impl GroupsSpecification {
include.contains(group) && !exclude.contains(group)
}
GroupsSpecification::Only { include, .. } => include.contains(group),
GroupsSpecification::Explicit { include } => include.contains(group),
}
}
}
Expand Down Expand Up @@ -178,6 +194,7 @@ impl DevGroupsSpecification {
only_dev: bool,
mut group: Vec<GroupName>,
no_group: Vec<GroupName>,
no_default_groups: bool,
mut only_group: Vec<GroupName>,
all_groups: bool,
) -> Self {
Expand All @@ -191,7 +208,12 @@ impl DevGroupsSpecification {
None
};

let groups = if all_groups {
let groups = if no_default_groups {
// Remove groups specified with `--no-group`.
group.retain(|group| !no_group.contains(group));

Some(GroupsSpecification::Explicit { include: group })
} else if all_groups {
Some(GroupsSpecification::Include {
include: IncludeGroups::All,
exclude: no_group,
Expand Down Expand Up @@ -376,6 +398,12 @@ impl DevGroupsManifest {
};
}

// If `--no-default-groups` was provided, only include group if it's explicitly
// included with `--group <group>`.
if let Some(GroupsSpecification::Explicit { include }) = self.spec.groups() {
return include.contains(group);
}

// If `--no-group` was provided, exclude the group from the list of defaults.
if let Some(GroupsSpecification::Include {
include: _,
Expand Down
40 changes: 36 additions & 4 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ impl RunSettings {
no_dev,
group,
no_group,
no_default_groups,
only_group,
all_groups,
module: _,
Expand Down Expand Up @@ -343,7 +344,14 @@ impl RunSettings {
extra.unwrap_or_default(),
),
dev: DevGroupsSpecification::from_args(
dev, no_dev, only_dev, group, no_group, only_group, all_groups,
dev,
no_dev,
only_dev,
group,
no_group,
no_default_groups,
only_group,
all_groups,
),
editable: EditableMode::from_args(no_editable),
modifications: if flag(exact, inexact).unwrap_or(false) {
Expand Down Expand Up @@ -960,6 +968,7 @@ impl SyncSettings {
only_dev,
group,
no_group,
no_default_groups,
only_group,
all_groups,
no_editable,
Expand Down Expand Up @@ -996,7 +1005,14 @@ impl SyncSettings {
extra.unwrap_or_default(),
),
dev: DevGroupsSpecification::from_args(
dev, no_dev, only_dev, group, no_group, only_group, all_groups,
dev,
no_dev,
only_dev,
group,
no_group,
no_default_groups,
only_group,
all_groups,
),
editable: EditableMode::from_args(no_editable),
install_options: InstallOptions::new(
Expand Down Expand Up @@ -1316,6 +1332,7 @@ impl TreeSettings {
no_dev,
group,
no_group,
no_default_groups,
only_group,
all_groups,
locked,
Expand All @@ -1334,7 +1351,14 @@ impl TreeSettings {

Self {
dev: DevGroupsSpecification::from_args(
dev, no_dev, only_dev, group, no_group, only_group, all_groups,
dev,
no_dev,
only_dev,
group,
no_group,
no_default_groups,
only_group,
all_groups,
),
locked,
frozen,
Expand Down Expand Up @@ -1397,6 +1421,7 @@ impl ExportSettings {
only_dev,
group,
no_group,
no_default_groups,
only_group,
all_groups,
header,
Expand Down Expand Up @@ -1432,7 +1457,14 @@ impl ExportSettings {
extra.unwrap_or_default(),
),
dev: DevGroupsSpecification::from_args(
dev, no_dev, only_dev, group, no_group, only_group, all_groups,
dev,
no_dev,
only_dev,
group,
no_group,
no_default_groups,
only_group,
all_groups,
),
editable: EditableMode::from_args(no_editable),
hashes: flag(hashes, no_hashes).unwrap_or(true),
Expand Down
Loading
Loading