Skip to content
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

Add uv add --no-sync and uv remove --no-sync #5881

Merged
merged 1 commit into from
Aug 7, 2024
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
8 changes: 8 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2297,6 +2297,10 @@ pub struct AddArgs {
#[arg(long)]
pub extra: Option<Vec<ExtraName>>,

/// Avoid syncing the virtual environment after re-locking the project.
#[arg(long, conflicts_with = "frozen")]
pub no_sync: bool,

/// Assert that the `uv.lock` will remain unchanged.
#[arg(long, conflicts_with = "frozen")]
pub locked: bool,
Expand Down Expand Up @@ -2355,6 +2359,10 @@ pub struct RemoveArgs {
#[arg(long, conflicts_with("dev"))]
pub optional: Option<ExtraName>,

/// Avoid syncing the virtual environment after re-locking the project.
#[arg(long, conflicts_with = "frozen")]
pub no_sync: bool,

/// Assert that the `uv.lock` will remain unchanged.
#[arg(long, conflicts_with = "frozen")]
pub locked: bool,
Expand Down
5 changes: 5 additions & 0 deletions crates/uv/src/commands/project/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::settings::ResolverInstallerSettings;
pub(crate) async fn add(
locked: bool,
frozen: bool,
no_sync: bool,
requirements: Vec<RequirementsSource>,
editable: Option<bool>,
dependency_type: DependencyType,
Expand Down Expand Up @@ -364,6 +365,10 @@ pub(crate) async fn add(
}
}

if no_sync {
return Ok(ExitStatus::Success);
}

// Sync the environment.
let (extras, dev) = match dependency_type {
DependencyType::Production => {
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/src/commands/project/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ use crate::printer::Printer;
use crate::settings::ResolverInstallerSettings;

/// Remove one or more packages from the project requirements.
#[allow(clippy::fn_params_excessive_bools)]
pub(crate) async fn remove(
locked: bool,
frozen: bool,
no_sync: bool,
requirements: Vec<PackageName>,
dependency_type: DependencyType,
package: Option<PackageName>,
Expand Down Expand Up @@ -120,6 +122,10 @@ pub(crate) async fn remove(
)
.await?;

if no_sync {
return Ok(ExitStatus::Success);
}

// Perform a full sync, because we don't know what exactly is affected by the removal.
// TODO(ibraheem): Should we accept CLI overrides for this? Should we even sync here?
let extras = ExtrasSpecification::All;
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ async fn run_project(
commands::add(
args.locked,
args.frozen,
args.no_sync,
args.requirements,
args.editable,
args.dependency_type,
Expand Down Expand Up @@ -1103,6 +1104,7 @@ async fn run_project(
commands::remove(
args.locked,
args.frozen,
args.no_sync,
args.requirements,
args.dependency_type,
args.package,
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ impl LockSettings {
pub(crate) struct AddSettings {
pub(crate) locked: bool,
pub(crate) frozen: bool,
pub(crate) no_sync: bool,
pub(crate) requirements: Vec<RequirementsSource>,
pub(crate) dependency_type: DependencyType,
pub(crate) editable: Option<bool>,
Expand Down Expand Up @@ -668,6 +669,7 @@ impl AddSettings {
rev,
tag,
branch,
no_sync,
locked,
frozen,
installer,
Expand All @@ -693,6 +695,7 @@ impl AddSettings {
Self {
locked,
frozen,
no_sync,
requirements,
dependency_type,
raw_sources,
Expand All @@ -718,6 +721,7 @@ impl AddSettings {
pub(crate) struct RemoveSettings {
pub(crate) locked: bool,
pub(crate) frozen: bool,
pub(crate) no_sync: bool,
pub(crate) requirements: Vec<PackageName>,
pub(crate) dependency_type: DependencyType,
pub(crate) package: Option<PackageName>,
Expand All @@ -734,6 +738,7 @@ impl RemoveSettings {
dev,
optional,
requirements,
no_sync,
locked,
frozen,
installer,
Expand All @@ -754,6 +759,7 @@ impl RemoveSettings {
Self {
locked,
frozen,
no_sync,
requirements,
dependency_type,
package,
Expand Down
51 changes: 50 additions & 1 deletion crates/uv/tests/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ fn add_git_implicit() -> Result<()> {
Installed 2 packages in [TIME]
- project==0.1.0 (from file://[TEMP_DIR]/)
+ project==0.1.0 (from file://[TEMP_DIR]/)
+ uv-public-pypackage==0.1.0 (from git+https://github.com/astral-test/uv-public-pypackage.git@b270df1a2fb5d012294e9aaf05e7e0bab1e6a389#b270df1a2fb5d012294e9aaf05e7e0bab1e6a389)
+ uv-public-pypackage==0.1.0 (from git+https://github.com/astral-test/uv-public-pypackage.git@b270df1a2fb5d012294e9aaf05e7e0bab1e6a389)
"###);

Ok(())
Expand Down Expand Up @@ -2136,6 +2136,55 @@ fn add_frozen() -> Result<()> {
Ok(())
}

/// Add a requirement without updating the environment.
#[test]
fn add_no_sync() -> Result<()> {
let context = TestContext::new("3.12");

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(indoc! {r#"
[project]
name = "project"
version = "0.1.0"
# ...
requires-python = ">=3.12"
dependencies = []
"#})?;

uv_snapshot!(context.filters(), context.add(&["anyio==3.7.0"]).arg("--no-sync"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
warning: `uv add` is experimental and may change without warning
Resolved 4 packages in [TIME]
"###);

let pyproject_toml = fs_err::read_to_string(context.temp_dir.join("pyproject.toml"))?;

insta::with_settings!({
filters => context.filters(),
}, {
assert_snapshot!(
pyproject_toml, @r###"
[project]
name = "project"
version = "0.1.0"
# ...
requires-python = ">=3.12"
dependencies = [
"anyio==3.7.0",
]
"###
);
});

assert!(context.temp_dir.join("uv.lock").exists());

Ok(())
}

#[test]
fn add_reject_multiple_git_ref_flags() {
let context = TestContext::new("3.12");
Expand Down
Loading