From ffdb283ec9211bedd48fa3779d8d44933ec74f86 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 31 Mar 2024 22:02:06 -0400 Subject: [PATCH] Add `pyproject.toml` et al to list of prompted packages (#2746) ## Summary If the user provides `uv pip install pyproject.toml`, we now prompt them to confirm that they meant the `pyproject-toml` package (as opposed to `uv pip install -r pyproject.toml`). --- crates/uv-requirements/src/sources.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/uv-requirements/src/sources.rs b/crates/uv-requirements/src/sources.rs index f6e98709e..6a375a7b3 100644 --- a/crates/uv-requirements/src/sources.rs +++ b/crates/uv-requirements/src/sources.rs @@ -93,11 +93,28 @@ impl RequirementsSource { let term = Term::stderr(); if term.is_term() { let prompt = format!( - "`{name}` looks like a requirements file but was passed as a package name. Did you mean `-r {name}`?" + "`{name}` looks like a local requirements file but was passed as a package name. Did you mean `-r {name}`?" ); let confirmation = confirm::confirm(&prompt, &term, true).unwrap(); if confirmation { - return Self::RequirementsTxt(name.into()); + return Self::from_requirements_file(name.into()); + } + } + } + + // Similarly, if the user provided a `pyproject.toml` file without `-r` (as in + // `uv pip install pyproject.toml`), prompt them to correct it. + if (name == "pyproject.toml" || name == "setup.py" || name == "setup.cfg") + && Path::new(&name).is_file() + { + let term = Term::stderr(); + if term.is_term() { + let prompt = format!( + "`{name}` looks like a local metadata file but was passed as a package name. Did you mean `-r {name}`?" + ); + let confirmation = confirm::confirm(&prompt, &term, true).unwrap(); + if confirmation { + return Self::from_requirements_file(name.into()); } } }