Add output when uv add and uv remove update scripts (#6231)

Closes https://github.com/astral-sh/uv/issues/6214
This commit is contained in:
Zanie Blue 2024-08-19 16:29:33 -05:00 committed by GitHub
parent e5bebe06b6
commit 5b74754140
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 14 deletions

View file

@ -1,4 +1,5 @@
use std::collections::hash_map::Entry;
use std::fmt::Write;
use std::path::{Path, PathBuf};
use anyhow::{bail, Context, Result};
@ -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::{
@ -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`

View file

@ -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};
@ -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.

View file

@ -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"))?;
@ -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"))?;
@ -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"))?;
@ -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"))?;
@ -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"))?;
@ -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"))?;
@ -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"))?;