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 2 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 @@ -2707,6 +2707,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 @@ -2972,6 +2978,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 @@ -3417,6 +3429,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 @@ -3581,6 +3599,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
32 changes: 27 additions & 5 deletions crates/uv-configuration/src/dev.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use either::Either;
use std::borrow::Cow;

use uv_normalize::{GroupName, DEV_DEPENDENCIES};

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -65,6 +65,10 @@ pub enum GroupsSpecification {
include: IncludeGroups,
exclude: Vec<GroupName>,
},
/// Explicitly include dependencies from the specified groups.
///
/// If the list is empty, no group will be included.
IncludeExplicitly(Vec<GroupName>),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't find a better naming and description.

/// 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 +90,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::IncludeExplicitly(_))
}

/// Returns `true` if the specification is limited to a select set of groups.
Expand Down Expand Up @@ -118,16 +122,24 @@ impl GroupsSpecification {
[group] => Some(Cow::Owned(format!("--only-group {group}"))),
[..] => Some(Cow::Borrowed("--only-group")),
},
Self::IncludeExplicitly(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 } => include.iter().chain(exclude.iter()),
GroupsSpecification::Only { include, exclude } => {
Either::Left(include.iter().chain(exclude.iter()))
}
GroupsSpecification::IncludeExplicitly(include) => Either::Right(include.iter()),
}
}

Expand All @@ -139,6 +151,7 @@ impl GroupsSpecification {
include.contains(group) && !exclude.contains(group)
}
GroupsSpecification::Only { include, .. } => include.contains(group),
GroupsSpecification::IncludeExplicitly(include) => include.contains(group),
}
}
}
Expand Down Expand Up @@ -178,6 +191,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 +205,9 @@ impl DevGroupsSpecification {
None
};

let groups = if all_groups {
let groups = if no_default_groups {
Some(GroupsSpecification::IncludeExplicitly(group))
} else if all_groups {
Some(GroupsSpecification::Include {
include: IncludeGroups::All,
exclude: no_group,
Expand Down Expand Up @@ -376,6 +392,12 @@ impl DevGroupsManifest {
};
}

// If `--no-default-groups` was provided, only include group if it's explicitly
// included with `--group <group>`.
if let Some(GroupsSpecification::IncludeExplicitly(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