Skip to content

Commit

Permalink
Add --group and --only-group to uv sync and includes all groups…
Browse files Browse the repository at this point in the history
… in `uv lock`
  • Loading branch information
zanieb committed Oct 10, 2024
1 parent 9d0e1e0 commit df853e8
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 10 deletions.
14 changes: 14 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2710,6 +2710,20 @@ pub struct SyncArgs {
#[arg(long, conflicts_with("no_dev"))]
pub only_dev: bool,

/// Include dependencies from the specified local dependency group.
///
/// May be provided multiple times.
#[arg(long, conflicts_with("only_group"))]
pub group: Vec<GroupName>,

/// Only include dependencies from the specified local dependency group.
///
/// May be provided multiple times.
///
/// The project itself will also be omitted.
#[arg(long, conflicts_with("group"))]
pub only_group: Vec<GroupName>,

/// Install any editable dependencies, including the project and any workspace members, as
/// non-editable.
#[arg(long)]
Expand Down
36 changes: 36 additions & 0 deletions crates/uv-configuration/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,39 @@ impl From<DevMode> for DevSpecification {
}
}
}

impl DevSpecification {
/// Determine the [`DevSpecification`] policy from the command-line arguments.
pub fn from_args(
dev: bool,
no_dev: bool,
only_dev: bool,
group: Vec<GroupName>,
only_group: Vec<GroupName>,
) -> Self {
let from_mode = DevSpecification::from(DevMode::from_args(dev, no_dev, only_dev));
if !group.is_empty() {
match from_mode {
DevSpecification::Exclude => Self::Include(group),
DevSpecification::Include(dev) => {
Self::Include(group.into_iter().chain(dev).collect())
}
DevSpecification::Only(_) => {
unreachable!("cannot specify both `--only-dev` and `--group`")
}
}
} else if !only_group.is_empty() {
match from_mode {
DevSpecification::Exclude => Self::Only(only_group),
DevSpecification::Only(dev) => {
Self::Only(only_group.into_iter().chain(dev).collect())
}
// TODO(zanieb): `dev` defaults to true we can't tell if `--dev` was provided in
// conflict with `--only-group` here
DevSpecification::Include(_) => Self::Only(only_group),
}
} else {
from_mode
}
}
}
8 changes: 7 additions & 1 deletion crates/uv/src/commands/project/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,13 @@ async fn do_lock(
let requirements = workspace.non_project_requirements().collect::<Vec<_>>();
let overrides = workspace.overrides().into_iter().collect::<Vec<_>>();
let constraints = workspace.constraints();
let dev = vec![DEV_DEPENDENCIES.clone()];
let dev: Vec<_> = workspace
.pyproject_toml()
.dependency_groups
.iter()
.flat_map(|groups| groups.keys().cloned())
.chain(std::iter::once(DEV_DEPENDENCIES.clone()))
.collect();
let source_trees = vec![];

// Collect the list of members.
Expand Down
6 changes: 3 additions & 3 deletions crates/uv/src/commands/project/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::str::FromStr;
use uv_cache::Cache;
use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::{
Concurrency, Constraints, DevMode, DevSpecification, EditableMode, ExtrasSpecification,
Concurrency, Constraints, DevSpecification, EditableMode, ExtrasSpecification,
HashCheckingMode, InstallOptions,
};
use uv_dispatch::BuildDispatch;
Expand All @@ -40,7 +40,7 @@ pub(crate) async fn sync(
frozen: bool,
package: Option<PackageName>,
extras: ExtrasSpecification,
dev: DevMode,
dev: DevSpecification,
editable: EditableMode,
install_options: InstallOptions,
modifications: Modifications,
Expand Down Expand Up @@ -149,7 +149,7 @@ pub(crate) async fn sync(
&venv,
&lock,
&extras,
&DevSpecification::from(dev),
&dev,
editable,
install_options,
modifications,
Expand Down
14 changes: 8 additions & 6 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use uv_cli::{
};
use uv_client::Connectivity;
use uv_configuration::{
BuildOptions, Concurrency, ConfigSettings, DevMode, EditableMode, ExportFormat,
ExtrasSpecification, HashCheckingMode, IndexStrategy, InstallOptions, KeyringProviderType,
NoBinary, NoBuild, PreviewMode, Reinstall, SourceStrategy, TargetTriple, TrustedHost,
TrustedPublishing, Upgrade, VersionControlSystem,
BuildOptions, Concurrency, ConfigSettings, DevMode, DevSpecification, EditableMode,
ExportFormat, ExtrasSpecification, HashCheckingMode, IndexStrategy, InstallOptions,
KeyringProviderType, NoBinary, NoBuild, PreviewMode, Reinstall, SourceStrategy, TargetTriple,
TrustedHost, TrustedPublishing, Upgrade, VersionControlSystem,
};
use uv_distribution_types::{DependencyMetadata, IndexLocations};
use uv_install_wheel::linker::LinkMode;
Expand Down Expand Up @@ -686,7 +686,7 @@ pub(crate) struct SyncSettings {
pub(crate) locked: bool,
pub(crate) frozen: bool,
pub(crate) extras: ExtrasSpecification,
pub(crate) dev: DevMode,
pub(crate) dev: DevSpecification,
pub(crate) editable: EditableMode,
pub(crate) install_options: InstallOptions,
pub(crate) modifications: Modifications,
Expand All @@ -707,6 +707,8 @@ impl SyncSettings {
dev,
no_dev,
only_dev,
group,
only_group,
no_editable,
inexact,
exact,
Expand Down Expand Up @@ -734,7 +736,7 @@ impl SyncSettings {
flag(all_extras, no_all_extras).unwrap_or_default(),
extra.unwrap_or_default(),
),
dev: DevMode::from_args(dev, no_dev, only_dev),
dev: DevSpecification::from_args(dev, no_dev, only_dev, group, only_group),
editable: EditableMode::from_args(no_editable),
install_options: InstallOptions::new(
no_install_project,
Expand Down
10 changes: 10 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,10 @@ uv sync [OPTIONS]

<p>Instead of checking if the lockfile is up-to-date, uses the versions in the lockfile as the source of truth. If the lockfile is missing, uv will exit with an error. If the <code>pyproject.toml</code> includes changes to dependencies that have not been included in the lockfile yet, they will not be present in the environment.</p>

</dd><dt><code>--group</code> <i>group</i></dt><dd><p>Include dependencies from the specified local dependency group.</p>

<p>May be provided multiple times.</p>

</dd><dt><code>--help</code>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>

</dd><dt><code>--index-strategy</code> <i>index-strategy</i></dt><dd><p>The strategy to use when resolving against multiple index URLs.</p>
Expand Down Expand Up @@ -1472,6 +1476,12 @@ uv sync [OPTIONS]

<p>The project itself will also be omitted.</p>

</dd><dt><code>--only-group</code> <i>only-group</i></dt><dd><p>Only include dependencies from the specified local dependency group.</p>

<p>May be provided multiple times.</p>

<p>The project itself will also be omitted.</p>

</dd><dt><code>--package</code> <i>package</i></dt><dd><p>Sync for a specific package in the workspace.</p>

<p>The workspace&#8217;s environment (<code>.venv</code>) is updated to reflect the subset of dependencies declared by the specified workspace member package.</p>
Expand Down

0 comments on commit df853e8

Please sign in to comment.