mirror of https://github.com/astral-sh/uv
Avoid eagerly reading input streams in `-r` (#16857)
## Summary I think the comment should explain it. Closes https://github.com/astral-sh/uv/issues/16856.
This commit is contained in:
parent
4bb219f8b9
commit
4d747f6e86
|
|
@ -32,7 +32,7 @@ pub enum RequirementsSource {
|
||||||
|
|
||||||
impl RequirementsSource {
|
impl RequirementsSource {
|
||||||
/// Parse a [`RequirementsSource`] from a [`PathBuf`]. The file type is determined by the file
|
/// Parse a [`RequirementsSource`] from a [`PathBuf`]. The file type is determined by the file
|
||||||
/// extension.
|
/// extension and, in some cases, the file contents.
|
||||||
pub fn from_requirements_file(path: PathBuf) -> Result<Self> {
|
pub fn from_requirements_file(path: PathBuf) -> Result<Self> {
|
||||||
if path.ends_with("pyproject.toml") {
|
if path.ends_with("pyproject.toml") {
|
||||||
Ok(Self::PyprojectToml(path))
|
Ok(Self::PyprojectToml(path))
|
||||||
|
|
@ -65,12 +65,13 @@ impl RequirementsSource {
|
||||||
.is_some_and(|ext| ext.eq_ignore_ascii_case("txt") || ext.eq_ignore_ascii_case("in"))
|
.is_some_and(|ext| ext.eq_ignore_ascii_case("txt") || ext.eq_ignore_ascii_case("in"))
|
||||||
{
|
{
|
||||||
Ok(Self::RequirementsTxt(path))
|
Ok(Self::RequirementsTxt(path))
|
||||||
} else if path == Path::new("-") || path == Path::new("/dev/stdin") {
|
} else if path.extension().is_none() && path.is_file() {
|
||||||
// If the path is `-`, treat it as a requirements.txt file from stdin.
|
|
||||||
Ok(Self::RequirementsTxt(path))
|
|
||||||
} else if path.extension().is_none() {
|
|
||||||
// If we don't have an extension, attempt to detect a PEP 723 script, and
|
// If we don't have an extension, attempt to detect a PEP 723 script, and
|
||||||
// fall back to `requirements.txt` format if not.
|
// fall back to `requirements.txt` format if not. (If the path isn't a file,
|
||||||
|
// we assume it's a readable file-like object in `requirements.txt` format, e.g.,
|
||||||
|
// `-r <( cat requirements.lock | grep -v nvidia | grep -v torch==)` or similar, in
|
||||||
|
// which case, reading the input would consume the stream, and only `requirements.txt`
|
||||||
|
// format is supported anyway.)
|
||||||
match Pep723Script::read_sync(&path) {
|
match Pep723Script::read_sync(&path) {
|
||||||
Ok(Some(script)) => Ok(Self::Pep723Script(Pep723ScriptSource::with_script(
|
Ok(Some(script)) => Ok(Self::Pep723Script(Pep723ScriptSource::with_script(
|
||||||
path, script,
|
path, script,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue