Skip to content

Commit 5c6e584

Browse files
Allow uv run arguments when reading from stdin (#10034)
## Summary Closes #10033.
1 parent bd03243 commit 5c6e584

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

crates/uv/src/commands/project/run.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ pub(crate) enum RunCommand {
11811181
/// [zipapp]: <https://docs.python.org/3/library/zipapp.html>
11821182
PythonZipapp(PathBuf, Vec<OsString>),
11831183
/// Execute a `python` script provided via `stdin`.
1184-
PythonStdin(Vec<u8>),
1184+
PythonStdin(Vec<u8>, Vec<OsString>),
11851185
/// Execute a Python script provided via a remote URL.
11861186
PythonRemote(tempfile::NamedTempFile, Vec<OsString>),
11871187
/// Execute an external command.
@@ -1208,7 +1208,7 @@ impl RunCommand {
12081208
Cow::Borrowed("python")
12091209
}
12101210
}
1211-
Self::PythonStdin(_) => Cow::Borrowed("python -c"),
1211+
Self::PythonStdin(..) => Cow::Borrowed("python -c"),
12121212
Self::External(executable, _) => executable.to_string_lossy(),
12131213
}
12141214
}
@@ -1261,7 +1261,7 @@ impl RunCommand {
12611261
process.args(args);
12621262
process
12631263
}
1264-
Self::PythonStdin(script) => {
1264+
Self::PythonStdin(script, args) => {
12651265
let mut process = Command::new(interpreter.sys_executable());
12661266
process.arg("-c");
12671267

@@ -1276,6 +1276,7 @@ impl RunCommand {
12761276
let script = String::from_utf8(script.clone()).expect("script is valid UTF-8");
12771277
process.arg(script);
12781278
}
1279+
process.args(args);
12791280

12801281
process
12811282
}
@@ -1414,7 +1415,7 @@ impl RunCommand {
14141415
if target.eq_ignore_ascii_case("-") {
14151416
let mut buf = Vec::with_capacity(1024);
14161417
std::io::stdin().read_to_end(&mut buf)?;
1417-
Ok(Self::PythonStdin(buf))
1418+
Ok(Self::PythonStdin(buf, args.to_vec()))
14181419
} else if target.eq_ignore_ascii_case("python") {
14191420
Ok(Self::Python(args.to_vec()))
14201421
} else if target_path

crates/uv/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
175175
Some(RunCommand::PythonRemote(script, _)) => {
176176
Pep723Metadata::read(&script).await?.map(Pep723Item::Remote)
177177
}
178-
Some(RunCommand::PythonStdin(contents)) => {
178+
Some(RunCommand::PythonStdin(contents, _)) => {
179179
Pep723Metadata::parse(contents)?.map(Pep723Item::Stdin)
180180
}
181181
_ => None,

crates/uv/tests/it/run.rs

+14
Original file line numberDiff line numberDiff line change
@@ -2493,6 +2493,20 @@ fn run_zipapp() -> Result<()> {
24932493
Ok(())
24942494
}
24952495

2496+
#[test]
2497+
fn run_stdin_args() {
2498+
let context = TestContext::new("3.12");
2499+
2500+
uv_snapshot!(context.filters(), context.run().arg("python").arg("-c").arg("import sys; print(sys.argv)").arg("foo").arg("bar"), @r###"
2501+
success: true
2502+
exit_code: 0
2503+
----- stdout -----
2504+
['-c', 'foo', 'bar']
2505+
2506+
----- stderr -----
2507+
"###);
2508+
}
2509+
24962510
/// Run a module equivalent to `python -m foo`.
24972511
#[test]
24982512
fn run_module() {

0 commit comments

Comments
 (0)