diff --git a/crates/uv/src/commands/project/run.rs b/crates/uv/src/commands/project/run.rs index 7921fee1be12a..e7266b49d8ea5 100644 --- a/crates/uv/src/commands/project/run.rs +++ b/crates/uv/src/commands/project/run.rs @@ -1181,7 +1181,7 @@ pub(crate) enum RunCommand { /// [zipapp]: PythonZipapp(PathBuf, Vec), /// Execute a `python` script provided via `stdin`. - PythonStdin(Vec), + PythonStdin(Vec, Vec), /// Execute a Python script provided via a remote URL. PythonRemote(tempfile::NamedTempFile, Vec), /// Execute an external command. @@ -1208,7 +1208,7 @@ impl RunCommand { Cow::Borrowed("python") } } - Self::PythonStdin(_) => Cow::Borrowed("python -c"), + Self::PythonStdin(..) => Cow::Borrowed("python -c"), Self::External(executable, _) => executable.to_string_lossy(), } } @@ -1261,7 +1261,7 @@ impl RunCommand { process.args(args); process } - Self::PythonStdin(script) => { + Self::PythonStdin(script, args) => { let mut process = Command::new(interpreter.sys_executable()); process.arg("-c"); @@ -1276,6 +1276,7 @@ impl RunCommand { let script = String::from_utf8(script.clone()).expect("script is valid UTF-8"); process.arg(script); } + process.args(args); process } @@ -1414,7 +1415,7 @@ impl RunCommand { if target.eq_ignore_ascii_case("-") { let mut buf = Vec::with_capacity(1024); std::io::stdin().read_to_end(&mut buf)?; - Ok(Self::PythonStdin(buf)) + Ok(Self::PythonStdin(buf, args.to_vec())) } else if target.eq_ignore_ascii_case("python") { Ok(Self::Python(args.to_vec())) } else if target_path diff --git a/crates/uv/src/lib.rs b/crates/uv/src/lib.rs index 9c8d87466c993..17a2e8581e8c1 100644 --- a/crates/uv/src/lib.rs +++ b/crates/uv/src/lib.rs @@ -175,7 +175,7 @@ async fn run(mut cli: Cli) -> Result { Some(RunCommand::PythonRemote(script, _)) => { Pep723Metadata::read(&script).await?.map(Pep723Item::Remote) } - Some(RunCommand::PythonStdin(contents)) => { + Some(RunCommand::PythonStdin(contents, _)) => { Pep723Metadata::parse(contents)?.map(Pep723Item::Stdin) } _ => None, diff --git a/crates/uv/tests/it/run.rs b/crates/uv/tests/it/run.rs index 8feecd781944a..3fd44aa22ef12 100644 --- a/crates/uv/tests/it/run.rs +++ b/crates/uv/tests/it/run.rs @@ -2493,6 +2493,20 @@ fn run_zipapp() -> Result<()> { Ok(()) } +#[test] +fn run_stdin_args() { + let context = TestContext::new("3.12"); + + uv_snapshot!(context.filters(), context.run().arg("python").arg("-c").arg("import sys; print(sys.argv)").arg("foo").arg("bar"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + ['-c', 'foo', 'bar'] + + ----- stderr ----- + "###); +} + /// Run a module equivalent to `python -m foo`. #[test] fn run_module() {