Skip to content

Commit

Permalink
Remove warnings for --frozen and --locked in uv run --script
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jan 22, 2025
1 parent a7166ff commit 30c00d0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
24 changes: 14 additions & 10 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down Expand Up @@ -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"
Expand Down
31 changes: 28 additions & 3 deletions crates/uv/tests/it/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 30c00d0

Please sign in to comment.