Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ pub(crate) enum RunCommand {
/// [zipapp]: <https://docs.python.org/3/library/zipapp.html>
PythonZipapp(PathBuf, Vec<OsString>),
/// Execute a `python` script provided via `stdin`.
PythonStdin(Vec<u8>),
PythonStdin(Vec<u8>, Vec<OsString>),
/// Execute a Python script provided via a remote URL.
PythonRemote(tempfile::NamedTempFile, Vec<OsString>),
/// Execute an external command.
Expand All @@ -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(),
}
}
Expand Down Expand Up @@ -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");

Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
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,
Expand Down
14 changes: 14 additions & 0 deletions crates/uv/tests/it/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down