From a3601eb9a1cdaac344f0fd57b3d74c9619d32cd7 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 23 Jul 2024 12:43:03 -0400 Subject: [PATCH] Reject stdin --- crates/uv-cli/src/lib.rs | 2 -- crates/uv/src/commands/project/run.rs | 5 ++++- crates/uv/tests/run.rs | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index c99ff3b418d0..6282017e4c17 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -1836,8 +1836,6 @@ pub struct RunArgs { /// Run with all packages listed in the given `requirements.txt` files. /// /// Using `pyproject.toml`, `setup.py`, or `setup.cfg` files is not allowed. - /// - /// If `-` is provided, then requirements will be read from stdin. #[arg(long, value_parser = parse_maybe_file_path)] pub with_requirements: Vec>, diff --git a/crates/uv/src/commands/project/run.rs b/crates/uv/src/commands/project/run.rs index eb9f6d14a943..bc072ee74051 100644 --- a/crates/uv/src/commands/project/run.rs +++ b/crates/uv/src/commands/project/run.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use std::ffi::OsString; use std::fmt::Write; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use anyhow::{bail, Context, Result}; use itertools::Itertools; @@ -72,6 +72,9 @@ pub(crate) async fn run( RequirementsSource::SetupCfg(_) => { bail!("Adding requirements from a `setup.cfg` is not supported in `uv run`"); } + RequirementsSource::RequirementsTxt(path) => if path == Path::new("-") { + bail!("Reading requirements from stdin is not supported in `uv run`"); + } _ => {} } } diff --git a/crates/uv/tests/run.rs b/crates/uv/tests/run.rs index 8fe85598f1cf..815d9866101b 100644 --- a/crates/uv/tests/run.rs +++ b/crates/uv/tests/run.rs @@ -700,5 +700,21 @@ fn run_requirements_txt() -> Result<()> { + sniffio==1.3.1 "###); + // But reject `-` as a requirements file. + uv_snapshot!(context.filters(), context.run() + .arg("--with-requirements") + .arg("-") + .arg("--with") + .arg("iniconfig") + .arg("main.py"), @r###" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + warning: `uv run` is experimental and may change without warning + error: Reading requirements from stdin is not supported in `uv run` + "###); + Ok(()) }