mirror of https://github.com/astral-sh/uv
Limit overrides and constraints to `requirements.txt` format (#2632)
## Summary I don't see a great reason to allow this, and it adds a lot of complexity, so `pyproject.toml` files are now limited to `pip compile` and `pip install -r` -- they can't be passed as `-c` or `--override`.
This commit is contained in:
parent
a632d2485b
commit
a7b251f65e
|
|
@ -4,6 +4,7 @@ use console::Term;
|
|||
|
||||
use uv_fs::Simplified;
|
||||
use uv_normalize::ExtraName;
|
||||
use uv_warnings::warn_user;
|
||||
|
||||
use crate::confirm;
|
||||
|
||||
|
|
@ -20,8 +21,9 @@ pub enum RequirementsSource {
|
|||
}
|
||||
|
||||
impl RequirementsSource {
|
||||
/// Parse a [`RequirementsSource`] from a [`PathBuf`].
|
||||
pub fn from_path(path: PathBuf) -> Self {
|
||||
/// Parse a [`RequirementsSource`] from a [`PathBuf`]. The file type is determined by the file
|
||||
/// extension.
|
||||
pub fn from_requirements_file(path: PathBuf) -> Self {
|
||||
if path.ends_with("pyproject.toml") {
|
||||
Self::PyprojectToml(path)
|
||||
} else {
|
||||
|
|
@ -29,6 +31,26 @@ impl RequirementsSource {
|
|||
}
|
||||
}
|
||||
|
||||
/// Parse a [`RequirementsSource`] from a constraints file.
|
||||
pub fn from_constraints_file(path: PathBuf) -> Self {
|
||||
if path.ends_with("pyproject.toml") {
|
||||
warn_user!(
|
||||
"The file `{}` appears to be a `pyproject.toml` file, but constraints must be specified in `requirements.txt` format.", path.user_display()
|
||||
);
|
||||
}
|
||||
Self::RequirementsTxt(path)
|
||||
}
|
||||
|
||||
/// Parse a [`RequirementsSource`] from an overrides file.
|
||||
pub fn from_overrides_file(path: PathBuf) -> Self {
|
||||
if path.ends_with("pyproject.toml") {
|
||||
warn_user!(
|
||||
"The file `{}` appears to be a `pyproject.toml` file, but overrides must be specified in `requirements.txt` format.", path.user_display()
|
||||
);
|
||||
}
|
||||
Self::RequirementsTxt(path)
|
||||
}
|
||||
|
||||
/// Parse a [`RequirementsSource`] from a user-provided string, assumed to be a package.
|
||||
///
|
||||
/// If the user provided a value that appears to be a `requirements.txt` file or a local
|
||||
|
|
|
|||
|
|
@ -1464,17 +1464,17 @@ async fn run() -> Result<ExitStatus> {
|
|||
let requirements = args
|
||||
.src_file
|
||||
.into_iter()
|
||||
.map(RequirementsSource::from_path)
|
||||
.map(RequirementsSource::from_requirements_file)
|
||||
.collect::<Vec<_>>();
|
||||
let constraints = args
|
||||
.constraint
|
||||
.into_iter()
|
||||
.map(RequirementsSource::from_path)
|
||||
.map(RequirementsSource::from_constraints_file)
|
||||
.collect::<Vec<_>>();
|
||||
let overrides = args
|
||||
.r#override
|
||||
.into_iter()
|
||||
.map(RequirementsSource::from_path)
|
||||
.map(RequirementsSource::from_overrides_file)
|
||||
.collect::<Vec<_>>();
|
||||
let index_urls = IndexLocations::new(
|
||||
args.index_url.and_then(Maybe::into_option),
|
||||
|
|
@ -1567,7 +1567,7 @@ async fn run() -> Result<ExitStatus> {
|
|||
let sources = args
|
||||
.src_file
|
||||
.into_iter()
|
||||
.map(RequirementsSource::from_path)
|
||||
.map(RequirementsSource::from_requirements_file)
|
||||
.collect::<Vec<_>>();
|
||||
let reinstall = Reinstall::from_args(args.reinstall, args.reinstall_package);
|
||||
let no_binary = NoBinary::from_args(args.no_binary);
|
||||
|
|
@ -1618,18 +1618,18 @@ async fn run() -> Result<ExitStatus> {
|
|||
.chain(
|
||||
args.requirement
|
||||
.into_iter()
|
||||
.map(RequirementsSource::from_path),
|
||||
.map(RequirementsSource::from_requirements_file),
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
let constraints = args
|
||||
.constraint
|
||||
.into_iter()
|
||||
.map(RequirementsSource::from_path)
|
||||
.map(RequirementsSource::from_constraints_file)
|
||||
.collect::<Vec<_>>();
|
||||
let overrides = args
|
||||
.r#override
|
||||
.into_iter()
|
||||
.map(RequirementsSource::from_path)
|
||||
.map(RequirementsSource::from_overrides_file)
|
||||
.collect::<Vec<_>>();
|
||||
let index_urls = IndexLocations::new(
|
||||
args.index_url.and_then(Maybe::into_option),
|
||||
|
|
@ -1714,7 +1714,7 @@ async fn run() -> Result<ExitStatus> {
|
|||
.chain(
|
||||
args.requirement
|
||||
.into_iter()
|
||||
.map(RequirementsSource::from_path),
|
||||
.map(RequirementsSource::from_requirements_file),
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
commands::pip_uninstall(
|
||||
|
|
|
|||
Loading…
Reference in New Issue