Skip to content

Commit

Permalink
Add output when uv add and uv remove update scripts (#6231)
Browse files Browse the repository at this point in the history
Closes #6214
  • Loading branch information
zanieb authored Aug 19, 2024
1 parent e5bebe0 commit 5b74754
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
17 changes: 13 additions & 4 deletions crates/uv/src/commands/project/add.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::hash_map::Entry;
use std::fmt::Write;
use std::path::{Path, PathBuf};

use anyhow::{bail, Context, Result};
Expand All @@ -15,7 +16,7 @@ use uv_configuration::{
};
use uv_dispatch::BuildDispatch;
use uv_distribution::DistributionDatabase;
use uv_fs::CWD;
use uv_fs::{Simplified, CWD};
use uv_git::GIT_STORE;
use uv_normalize::PackageName;
use uv_python::{
Expand Down Expand Up @@ -425,9 +426,17 @@ pub(crate) async fn add(
}
};

// If `--script`, exit early. There's no reason to lock and sync.
let Target::Project(project, venv) = target else {
return Ok(ExitStatus::Success);
let (project, venv) = match target {
Target::Project(project, venv) => (project, venv),
// If `--script`, exit early. There's no reason to lock and sync.
Target::Script(script, _) => {
writeln!(
printer.stderr(),
"Updated `{}`",
script.path.user_display().cyan()
)?;
return Ok(ExitStatus::Success);
}
};

// If `--frozen`, exit early. There's no reason to lock and sync, and we don't need a `uv.lock`
Expand Down
19 changes: 15 additions & 4 deletions crates/uv/src/commands/project/remove.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::fmt::Write;

use anyhow::{Context, Result};

use owo_colors::OwoColorize;
use pep508_rs::PackageName;
use uv_cache::Cache;
use uv_client::Connectivity;
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode};
use uv_fs::CWD;
use uv_fs::{Simplified, CWD};
use uv_python::{PythonDownloads, PythonPreference, PythonRequest};
use uv_scripts::Pep723Script;
use uv_warnings::{warn_user, warn_user_once};
Expand Down Expand Up @@ -141,9 +144,17 @@ pub(crate) async fn remove(
return Ok(ExitStatus::Success);
}

// If `--script`, exit early. There's no reason to lock and sync.
let Target::Project(project) = target else {
return Ok(ExitStatus::Success);
let project = match target {
Target::Project(project) => project,
// If `--script`, exit early. There's no reason to lock and sync.
Target::Script(script) => {
writeln!(
printer.stderr(),
"Updated `{}`",
script.path.user_display().cyan()
)?;
return Ok(ExitStatus::Success);
}
};

// Discover or create the virtual environment.
Expand Down
19 changes: 13 additions & 6 deletions crates/uv/tests/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3536,13 +3536,14 @@ fn add_script() -> Result<()> {
pprint([(k, v["title"]) for k, v in data.items()][:10])
"#})?;

uv_snapshot!(context.filters(), context.add(&["anyio"]).arg("--script").arg(script.path()), @r###"
uv_snapshot!(context.filters(), context.add(&["anyio"]).arg("--script").arg("script.py"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
warning: `uv add` is experimental and may change without warning
Updated `script.py`
"###);

let script_content = fs_err::read_to_string(context.temp_dir.join("script.py"))?;
Expand Down Expand Up @@ -3588,13 +3589,14 @@ fn add_script_without_metadata_table() -> Result<()> {
pprint([(k, v["title"]) for k, v in data.items()][:10])
"#})?;

uv_snapshot!(context.filters(), context.add(&["rich", "requests<3"]).arg("--script").arg(script.path()), @r###"
uv_snapshot!(context.filters(), context.add(&["rich", "requests<3"]).arg("--script").arg("script.py"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
warning: `uv add` is experimental and may change without warning
Updated `script.py`
"###);

let script_content = fs_err::read_to_string(context.temp_dir.join("script.py"))?;
Expand Down Expand Up @@ -3639,13 +3641,14 @@ fn add_script_without_metadata_table_with_shebang() -> Result<()> {
pprint([(k, v["title"]) for k, v in data.items()][:10])
"#})?;

uv_snapshot!(context.filters(), context.add(&["rich", "requests<3"]).arg("--script").arg(script.path()), @r###"
uv_snapshot!(context.filters(), context.add(&["rich", "requests<3"]).arg("--script").arg("script.py"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
warning: `uv add` is experimental and may change without warning
Updated `script.py`
"###);

let script_content = fs_err::read_to_string(context.temp_dir.join("script.py"))?;
Expand Down Expand Up @@ -3691,13 +3694,14 @@ fn add_script_without_metadata_table_with_docstring() -> Result<()> {
pprint([(k, v["title"]) for k, v in data.items()][:10])
"#})?;

uv_snapshot!(context.filters(), context.add(&["rich", "requests<3"]).arg("--script").arg(script.path()), @r###"
uv_snapshot!(context.filters(), context.add(&["rich", "requests<3"]).arg("--script").arg("script.py"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
warning: `uv add` is experimental and may change without warning
Updated `script.py`
"###);

let script_content = fs_err::read_to_string(context.temp_dir.join("script.py"))?;
Expand Down Expand Up @@ -3751,13 +3755,14 @@ fn remove_script() -> Result<()> {
pprint([(k, v["title"]) for k, v in data.items()][:10])
"#})?;

uv_snapshot!(context.filters(), context.remove(&["anyio"]).arg("--script").arg(script.path()), @r###"
uv_snapshot!(context.filters(), context.remove(&["anyio"]).arg("--script").arg("script.py"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
warning: `uv remove` is experimental and may change without warning
Updated `script.py`
"###);

let script_content = fs_err::read_to_string(context.temp_dir.join("script.py"))?;
Expand Down Expand Up @@ -3809,13 +3814,14 @@ fn remove_last_dep_script() -> Result<()> {
pprint([(k, v["title"]) for k, v in data.items()][:10])
"#})?;

uv_snapshot!(context.filters(), context.remove(&["rich"]).arg("--script").arg(script.path()), @r###"
uv_snapshot!(context.filters(), context.remove(&["rich"]).arg("--script").arg("script.py"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
warning: `uv remove` is experimental and may change without warning
Updated `script.py`
"###);

let script_content = fs_err::read_to_string(context.temp_dir.join("script.py"))?;
Expand Down Expand Up @@ -3890,6 +3896,7 @@ fn add_git_to_script() -> Result<()> {
----- stdout -----
----- stderr -----
Updated `script.py`
"###);

let script_content = fs_err::read_to_string(context.temp_dir.join("script.py"))?;
Expand Down

0 comments on commit 5b74754

Please sign in to comment.