Remove warnings for --frozen and --locked in uv run --script (#10840)

## Summary

We only show these if a lockfile is missing; and, if so, we guide the
user towards generating one.

Closes https://github.com/astral-sh/uv/issues/10839.
This commit is contained in:
Charlie Marsh
2025-01-22 08:19:28 -05:00
committed by GitHub
parent dc637d0b7b
commit 028df07c19
2 changed files with 42 additions and 13 deletions
+14 -10
View File
@@ -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"
+28 -3
View File
@@ -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 <module>
import anyio