Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading