Skip to content

Commit

Permalink
Allow --gui-script on Unix (#9787)
Browse files Browse the repository at this point in the history
To match `uv run foo.pyw` behavior from
#9759
  • Loading branch information
zanieb authored Dec 10, 2024
1 parent 6772cf8 commit a090cf1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
5 changes: 1 addition & 4 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,10 +1404,7 @@ impl RunCommand {
} else if script {
return Ok(Self::PythonScript(target.clone().into(), args.to_vec()));
} else if gui_script {
if cfg!(windows) {
return Ok(Self::PythonGuiScript(target.clone().into(), args.to_vec()));
}
anyhow::bail!("`--gui-script` is only supported on Windows. Did you mean `--script`?");
return Ok(Self::PythonGuiScript(target.clone().into(), args.to_vec()));
}

let metadata = target_path.metadata();
Expand Down
19 changes: 13 additions & 6 deletions crates/uv/tests/it/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2895,7 +2895,7 @@ fn run_script_explicit_directory() -> Result<()> {

#[test]
#[cfg(windows)]
fn run_gui_script_explicit() -> Result<()> {
fn run_gui_script_explicit_windows() -> Result<()> {
let context = TestContext::new("3.12");

let test_script = context.temp_dir.child("script");
Expand Down Expand Up @@ -2932,24 +2932,31 @@ fn run_gui_script_explicit() -> Result<()> {

#[test]
#[cfg(not(windows))]
fn run_gui_script_not_supported() -> Result<()> {
fn run_gui_script_explicit_unix() -> Result<()> {
let context = TestContext::new("3.12");
let test_script = context.temp_dir.child("script");
test_script.write_str(indoc! { r#"
# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
print("Hello")
import sys
import os
executable = os.path.basename(sys.executable).lower()
print(f"Using executable: {executable}", file=sys.stderr)
"#})?;

uv_snapshot!(context.filters(), context.run().arg("--gui-script").arg("script"), @r###"
success: false
exit_code: 2
success: true
exit_code: 0
----- stdout -----
----- stderr -----
error: `--gui-script` is only supported on Windows. Did you mean `--script`?
Reading inline script metadata from `script`
Resolved in [TIME]
Audited in [TIME]
Using executable: python3
"###);

Ok(())
Expand Down

0 comments on commit a090cf1

Please sign in to comment.