mirror of
				https://github.com/astral-sh/uv.git
				synced 2025-11-04 05:34:28 +00:00 
			
		
		
		
	Allow execution of pyw files on Unix (#9759)
I don't see any real reason to forbid executing these in a
cross-platform way
```
❯ echo "print('hello world')" > test.pyw
❯ uv run test.pyw
error: Failed to spawn: `test.pyw`
  Caused by: No such file or directory (os error 2)
❯ cargo run -q -- run test.pyw
hello world
```
Closes https://github.com/astral-sh/uv/issues/9757
			
			
This commit is contained in:
		
							parent
							
								
									341126cf72
								
							
						
					
					
						commit
						5e5635c142
					
				
					 2 changed files with 11 additions and 7 deletions
				
			
		| 
						 | 
					@ -1173,7 +1173,7 @@ pub(crate) enum RunCommand {
 | 
				
			||||||
    /// Search `sys.path` for the named module and execute its contents as the `__main__` module.
 | 
					    /// Search `sys.path` for the named module and execute its contents as the `__main__` module.
 | 
				
			||||||
    /// Equivalent to `python -m module`.
 | 
					    /// Equivalent to `python -m module`.
 | 
				
			||||||
    PythonModule(OsString, Vec<OsString>),
 | 
					    PythonModule(OsString, Vec<OsString>),
 | 
				
			||||||
    /// Execute a `pythonw` script (Windows only).
 | 
					    /// Execute a `pythonw` GUI script.
 | 
				
			||||||
    PythonGuiScript(PathBuf, Vec<OsString>),
 | 
					    PythonGuiScript(PathBuf, Vec<OsString>),
 | 
				
			||||||
    /// Execute a Python package containing a `__main__.py` file.
 | 
					    /// Execute a Python package containing a `__main__.py` file.
 | 
				
			||||||
    PythonPackage(PathBuf, Vec<OsString>),
 | 
					    PythonPackage(PathBuf, Vec<OsString>),
 | 
				
			||||||
| 
						 | 
					@ -1201,7 +1201,13 @@ impl RunCommand {
 | 
				
			||||||
            | Self::PythonRemote(..)
 | 
					            | Self::PythonRemote(..)
 | 
				
			||||||
            | Self::Empty => Cow::Borrowed("python"),
 | 
					            | Self::Empty => Cow::Borrowed("python"),
 | 
				
			||||||
            Self::PythonModule(..) => Cow::Borrowed("python -m"),
 | 
					            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::PythonStdin(_) => Cow::Borrowed("python -c"),
 | 
				
			||||||
            Self::External(executable, _) => executable.to_string_lossy(),
 | 
					            Self::External(executable, _) => executable.to_string_lossy(),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -1413,8 +1419,7 @@ impl RunCommand {
 | 
				
			||||||
            && is_file
 | 
					            && is_file
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Ok(Self::PythonScript(target_path, args.to_vec()))
 | 
					            Ok(Self::PythonScript(target_path, args.to_vec()))
 | 
				
			||||||
        } else if cfg!(windows)
 | 
					        } else if target_path
 | 
				
			||||||
            && target_path
 | 
					 | 
				
			||||||
            .extension()
 | 
					            .extension()
 | 
				
			||||||
            .is_some_and(|ext| ext.eq_ignore_ascii_case("pyw"))
 | 
					            .is_some_and(|ext| ext.eq_ignore_ascii_case("pyw"))
 | 
				
			||||||
            && is_file
 | 
					            && is_file
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -542,7 +542,6 @@ fn run_pep723_script_requires_python() -> Result<()> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Run a `.pyw` script. The script should be executed with `pythonw.exe`.
 | 
					/// Run a `.pyw` script. The script should be executed with `pythonw.exe`.
 | 
				
			||||||
#[test]
 | 
					#[test]
 | 
				
			||||||
#[cfg(windows)]
 | 
					 | 
				
			||||||
fn run_pythonw_script() -> Result<()> {
 | 
					fn run_pythonw_script() -> Result<()> {
 | 
				
			||||||
    let context = TestContext::new("3.12");
 | 
					    let context = TestContext::new("3.12");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue