Allow `--gui-script` on Unix (#9787)

To match `uv run foo.pyw` behavior from
https://github.com/astral-sh/uv/pull/9759
This commit is contained in:
Zanie Blue 2024-12-10 15:13:17 -06:00 committed by GitHub
parent 6772cf8ac3
commit a090cf1f12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 10 deletions

View File

@ -1404,10 +1404,7 @@ impl RunCommand {
} else if script { } else if script {
return Ok(Self::PythonScript(target.clone().into(), args.to_vec())); return Ok(Self::PythonScript(target.clone().into(), args.to_vec()));
} else if gui_script { } else if gui_script {
if cfg!(windows) { return Ok(Self::PythonGuiScript(target.clone().into(), args.to_vec()));
return Ok(Self::PythonGuiScript(target.clone().into(), args.to_vec()));
}
anyhow::bail!("`--gui-script` is only supported on Windows. Did you mean `--script`?");
} }
let metadata = target_path.metadata(); let metadata = target_path.metadata();

View File

@ -2895,7 +2895,7 @@ fn run_script_explicit_directory() -> Result<()> {
#[test] #[test]
#[cfg(windows)] #[cfg(windows)]
fn run_gui_script_explicit() -> Result<()> { fn run_gui_script_explicit_windows() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");
let test_script = context.temp_dir.child("script"); let test_script = context.temp_dir.child("script");
@ -2932,7 +2932,7 @@ fn run_gui_script_explicit() -> Result<()> {
#[test] #[test]
#[cfg(not(windows))] #[cfg(not(windows))]
fn run_gui_script_not_supported() -> Result<()> { fn run_gui_script_explicit_unix() -> Result<()> {
let context = TestContext::new("3.12"); let context = TestContext::new("3.12");
let test_script = context.temp_dir.child("script"); let test_script = context.temp_dir.child("script");
test_script.write_str(indoc! { r#" test_script.write_str(indoc! { r#"
@ -2940,16 +2940,23 @@ fn run_gui_script_not_supported() -> Result<()> {
# requires-python = ">=3.11" # requires-python = ">=3.11"
# dependencies = [] # 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###" uv_snapshot!(context.filters(), context.run().arg("--gui-script").arg("script"), @r###"
success: false success: true
exit_code: 2 exit_code: 0
----- stdout ----- ----- stdout -----
----- stderr ----- ----- 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(()) Ok(())