From 30c00d0ef0f3e0a2466b5aa403bb93ae2e7c2582 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 21 Jan 2025 21:21:39 -0500 Subject: [PATCH] Remove warnings for --frozen and --locked in uv run --script --- crates/uv/src/commands/project/run.rs | 24 ++++++++++++--------- crates/uv/tests/it/run.rs | 31 ++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/crates/uv/src/commands/project/run.rs b/crates/uv/src/commands/project/run.rs index 777d5472c7e1..65ef8b76fb72 100644 --- a/crates/uv/src/commands/project/run.rs +++ b/crates/uv/src/commands/project/run.rs @@ -285,6 +285,20 @@ pub(crate) async fn run( Some(environment.into_interpreter()) } else { + // If no lockfile is found, warn against `--locked` and `--frozen`. + if locked { + warn_user!( + "No lockfile found for Python script (ignoring `--locked`); run `{}` to generate a lockfile", + "uv lock --script".green(), + ); + } + if frozen { + warn_user!( + "No lockfile found for Python script (ignoring `--frozen`); run `{}` to generate a lockfile", + "uv lock --script".green(), + ); + } + // Determine the working directory for the script. let script_dir = match &script { Pep723Item::Script(script) => std::path::absolute(&script.path)? @@ -470,16 +484,6 @@ pub(crate) async fn run( "`--package` is a no-op for Python scripts with inline metadata, which always run in isolation" ); } - if locked { - warn_user!( - "`--locked` is a no-op for Python scripts with inline metadata, which always run in isolation" - ); - } - if frozen { - warn_user!( - "`--frozen` is a no-op for Python scripts with inline metadata, which always run in isolation" - ); - } if no_sync { warn_user!( "`--no-sync` is a no-op for Python scripts with inline metadata, which always run in isolation" diff --git a/crates/uv/tests/it/run.rs b/crates/uv/tests/it/run.rs index 05c95f4841c3..d2dbc41ce01a 100644 --- a/crates/uv/tests/it/run.rs +++ b/crates/uv/tests/it/run.rs @@ -401,7 +401,7 @@ fn run_pep723_script() -> Result<()> { Hello, world! ----- stderr ----- - warning: `--locked` is a no-op for Python scripts with inline metadata, which always run in isolation + warning: No lockfile found for Python script (ignoring `--locked`); run `uv lock --script` to generate a lockfile "###); // If the script can't be resolved, we should reference the script. @@ -784,6 +784,21 @@ fn run_pep723_script_lock() -> Result<()> { "# })?; + // Without a lockfile, running with `--locked` should warn. + uv_snapshot!(context.filters(), context.run().arg("--locked").arg("main.py"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + Hello, world! + + ----- stderr ----- + warning: No lockfile found for Python script (ignoring `--locked`); run `uv lock --script` to generate a lockfile + Resolved 1 package in [TIME] + Prepared 1 package in [TIME] + Installed 1 package in [TIME] + + iniconfig==2.0.0 + "###); + // Explicitly lock the script. uv_snapshot!(context.filters(), context.lock().arg("--script").arg("main.py"), @r###" success: true @@ -822,6 +837,7 @@ fn run_pep723_script_lock() -> Result<()> { ); }); + // Run the script. uv_snapshot!(context.filters(), context.run().arg("main.py"), @r###" success: true exit_code: 0 @@ -830,11 +846,21 @@ fn run_pep723_script_lock() -> Result<()> { ----- stderr ----- Resolved 1 package in [TIME] - Prepared 1 package in [TIME] Installed 1 package in [TIME] + iniconfig==2.0.0 "###); + // With a lockfile, running with `--locked` should not warn. + uv_snapshot!(context.filters(), context.run().arg("--locked").arg("main.py"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + Hello, world! + + ----- stderr ----- + Resolved 1 package in [TIME] + "###); + // Modify the metadata. test_script.write_str(indoc! { r#" # /// script @@ -868,7 +894,6 @@ fn run_pep723_script_lock() -> Result<()> { ----- stdout ----- ----- stderr ----- - warning: `--frozen` is a no-op for Python scripts with inline metadata, which always run in isolation Traceback (most recent call last): File "[TEMP_DIR]/main.py", line 8, in import anyio