From 932353191fe8dc58ea1c8f1e2d5c8882bd410cef Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 9 Dec 2024 18:56:30 -0600 Subject: [PATCH] Allow execution of pyw files on Unix --- crates/uv/src/commands/project/run.rs | 17 +++++++++++------ crates/uv/tests/it/run.rs | 1 - 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/uv/src/commands/project/run.rs b/crates/uv/src/commands/project/run.rs index 9ce55a3c72e85..165709c111166 100644 --- a/crates/uv/src/commands/project/run.rs +++ b/crates/uv/src/commands/project/run.rs @@ -1173,7 +1173,7 @@ pub(crate) enum RunCommand { /// Search `sys.path` for the named module and execute its contents as the `__main__` module. /// Equivalent to `python -m module`. PythonModule(OsString, Vec), - /// Execute a `pythonw` script (Windows only). + /// Execute a `pythonw` GUI script. PythonGuiScript(PathBuf, Vec), /// Execute a Python package containing a `__main__.py` file. PythonPackage(PathBuf, Vec), @@ -1201,7 +1201,13 @@ impl RunCommand { | Self::PythonRemote(..) | Self::Empty => Cow::Borrowed("python"), Self::PythonModule(..) => Cow::Borrowed("python -m"), - Self::PythonGuiScript(..) => Cow::Borrowed("pythonw"), + Self::PythonGuiScript(..) => { + if cfg!(windows) { + Cow::Borrowed("pythonw") + } else { + Cow::Borrowed("python") + } + } Self::PythonStdin(_) => Cow::Borrowed("python -c"), Self::External(executable, _) => executable.to_string_lossy(), } @@ -1413,10 +1419,9 @@ impl RunCommand { && is_file { Ok(Self::PythonScript(target_path, args.to_vec())) - } else if cfg!(windows) - && target_path - .extension() - .is_some_and(|ext| ext.eq_ignore_ascii_case("pyw")) + } else if target_path + .extension() + .is_some_and(|ext| ext.eq_ignore_ascii_case("pyw")) && is_file { Ok(Self::PythonGuiScript(target_path, args.to_vec())) diff --git a/crates/uv/tests/it/run.rs b/crates/uv/tests/it/run.rs index cf7de5dae1ae2..5f758bb4e13f6 100644 --- a/crates/uv/tests/it/run.rs +++ b/crates/uv/tests/it/run.rs @@ -542,7 +542,6 @@ fn run_pep723_script_requires_python() -> Result<()> { /// Run a `.pyw` script. The script should be executed with `pythonw.exe`. #[test] -#[cfg(windows)] fn run_pythonw_script() -> Result<()> { let context = TestContext::new("3.12");