Skip to content

Commit c51b8d3

Browse files
committed
Remove warnings for --frozen and --locked in uv run --script
1 parent a7166ff commit c51b8d3

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

crates/uv/src/commands/project/run.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,20 @@ pub(crate) async fn run(
285285

286286
Some(environment.into_interpreter())
287287
} else {
288+
// If no lockfile is found, warn against `--locked` and `--frozen`.
289+
if locked {
290+
warn_user!(
291+
"No lockfile found for Python script (ignoring `--locked`); run `{}` to generate a lockfile",
292+
"uv lock --script".green(),
293+
);
294+
}
295+
if frozen {
296+
warn_user!(
297+
"No lockfile found for Python script (ignoring `--frozen`); run `{}` to generate a lockfile",
298+
"uv lock --script".green(),
299+
);
300+
}
301+
288302
// Determine the working directory for the script.
289303
let script_dir = match &script {
290304
Pep723Item::Script(script) => std::path::absolute(&script.path)?
@@ -470,16 +484,6 @@ pub(crate) async fn run(
470484
"`--package` is a no-op for Python scripts with inline metadata, which always run in isolation"
471485
);
472486
}
473-
if locked {
474-
warn_user!(
475-
"`--locked` is a no-op for Python scripts with inline metadata, which always run in isolation"
476-
);
477-
}
478-
if frozen {
479-
warn_user!(
480-
"`--frozen` is a no-op for Python scripts with inline metadata, which always run in isolation"
481-
);
482-
}
483487
if no_sync {
484488
warn_user!(
485489
"`--no-sync` is a no-op for Python scripts with inline metadata, which always run in isolation"

crates/uv/tests/it/run.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,21 @@ fn run_pep723_script_lock() -> Result<()> {
784784
"#
785785
})?;
786786

787+
// Without a lockfile, running with `--locked` should warn.
788+
uv_snapshot!(context.filters(), context.run().arg("--locked").arg("main.py"), @r###"
789+
success: true
790+
exit_code: 0
791+
----- stdout -----
792+
Hello, world!
793+
794+
----- stderr -----
795+
warning: No lockfile found for Python script (ignoring `--locked`); run `uv lock --script` to generate a lockfile
796+
Resolved 1 package in [TIME]
797+
Prepared 1 package in [TIME]
798+
Installed 1 package in [TIME]
799+
+ iniconfig==2.0.0
800+
"###);
801+
787802
// Explicitly lock the script.
788803
uv_snapshot!(context.filters(), context.lock().arg("--script").arg("main.py"), @r###"
789804
success: true
@@ -822,6 +837,7 @@ fn run_pep723_script_lock() -> Result<()> {
822837
);
823838
});
824839

840+
// Run the script.
825841
uv_snapshot!(context.filters(), context.run().arg("main.py"), @r###"
826842
success: true
827843
exit_code: 0
@@ -830,11 +846,21 @@ fn run_pep723_script_lock() -> Result<()> {
830846
831847
----- stderr -----
832848
Resolved 1 package in [TIME]
833-
Prepared 1 package in [TIME]
834849
Installed 1 package in [TIME]
835850
+ iniconfig==2.0.0
836851
"###);
837852

853+
// With a lockfile, running with `--locked` should not warn.
854+
uv_snapshot!(context.filters(), context.run().arg("--locked").arg("main.py"), @r###"
855+
success: true
856+
exit_code: 0
857+
----- stdout -----
858+
Hello, world!
859+
860+
----- stderr -----
861+
Resolved 1 package in [TIME]
862+
"###);
863+
838864
// Modify the metadata.
839865
test_script.write_str(indoc! { r#"
840866
# /// script
@@ -868,7 +894,6 @@ fn run_pep723_script_lock() -> Result<()> {
868894
----- stdout -----
869895
870896
----- stderr -----
871-
warning: `--frozen` is a no-op for Python scripts with inline metadata, which always run in isolation
872897
Traceback (most recent call last):
873898
File "[TEMP_DIR]/main.py", line 8, in <module>
874899
import anyio

0 commit comments

Comments
 (0)