mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-31 15:57:26 +00:00
Add --no-build
, --no-build-package
, and binary variants (#4322)
## Summary These are now supported on `uv run`, `uv lock`, `uv sync`, and `uv tool run`. Closes https://github.com/astral-sh/uv/issues/4297.
This commit is contained in:
parent
f01ab57518
commit
7d9541d0f4
19 changed files with 700 additions and 434 deletions
|
@ -46,6 +46,14 @@ impl BuildOptions {
|
|||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn combine(self, no_binary: NoBinary, no_build: NoBuild) -> Self {
|
||||
Self {
|
||||
no_binary: self.no_binary.combine(no_binary),
|
||||
no_build: self.no_build.combine(no_build),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn no_binary_package(&self, package_name: &PackageName) -> bool {
|
||||
match &self.no_binary {
|
||||
NoBinary::None => false,
|
||||
|
@ -108,7 +116,22 @@ pub enum NoBinary {
|
|||
|
||||
impl NoBinary {
|
||||
/// Determine the binary installation strategy to use for the given arguments.
|
||||
pub fn from_args(no_binary: Vec<PackageNameSpecifier>) -> Self {
|
||||
pub fn from_args(no_binary: Option<bool>, no_binary_package: Vec<PackageName>) -> Self {
|
||||
match no_binary {
|
||||
Some(true) => Self::All,
|
||||
Some(false) => Self::None,
|
||||
None => {
|
||||
if no_binary_package.is_empty() {
|
||||
Self::None
|
||||
} else {
|
||||
Self::Packages(no_binary_package)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Determine the binary installation strategy to use for the given arguments from the pip CLI.
|
||||
pub fn from_pip_args(no_binary: Vec<PackageNameSpecifier>) -> Self {
|
||||
let combined = PackageNameSpecifiers::from_iter(no_binary.into_iter());
|
||||
match combined {
|
||||
PackageNameSpecifiers::All => Self::All,
|
||||
|
@ -117,9 +140,9 @@ impl NoBinary {
|
|||
}
|
||||
}
|
||||
|
||||
/// Determine the binary installation strategy to use for the given argument.
|
||||
pub fn from_arg(no_binary: PackageNameSpecifier) -> Self {
|
||||
Self::from_args(vec![no_binary])
|
||||
/// Determine the binary installation strategy to use for the given argument from the pip CLI.
|
||||
pub fn from_pip_arg(no_binary: PackageNameSpecifier) -> Self {
|
||||
Self::from_pip_args(vec![no_binary])
|
||||
}
|
||||
|
||||
/// Combine a set of [`NoBinary`] values.
|
||||
|
@ -188,7 +211,22 @@ pub enum NoBuild {
|
|||
|
||||
impl NoBuild {
|
||||
/// Determine the build strategy to use for the given arguments.
|
||||
pub fn from_args(only_binary: Vec<PackageNameSpecifier>, no_build: bool) -> Self {
|
||||
pub fn from_args(no_build: Option<bool>, no_build_package: Vec<PackageName>) -> Self {
|
||||
match no_build {
|
||||
Some(true) => Self::All,
|
||||
Some(false) => Self::None,
|
||||
None => {
|
||||
if no_build_package.is_empty() {
|
||||
Self::None
|
||||
} else {
|
||||
Self::Packages(no_build_package)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Determine the build strategy to use for the given arguments from the pip CLI.
|
||||
pub fn from_pip_args(only_binary: Vec<PackageNameSpecifier>, no_build: bool) -> Self {
|
||||
if no_build {
|
||||
Self::All
|
||||
} else {
|
||||
|
@ -201,9 +239,9 @@ impl NoBuild {
|
|||
}
|
||||
}
|
||||
|
||||
/// Determine the build strategy to use for the given argument.
|
||||
pub fn from_arg(no_build: PackageNameSpecifier) -> Self {
|
||||
Self::from_args(vec![no_build], false)
|
||||
/// Determine the build strategy to use for the given argument from the pip CLI.
|
||||
pub fn from_pip_arg(no_build: PackageNameSpecifier) -> Self {
|
||||
Self::from_pip_args(vec![no_build], false)
|
||||
}
|
||||
|
||||
/// Combine a set of [`NoBuild`] values.
|
||||
|
@ -310,23 +348,23 @@ mod tests {
|
|||
#[test]
|
||||
fn no_build_from_args() -> Result<(), Error> {
|
||||
assert_eq!(
|
||||
NoBuild::from_args(vec![PackageNameSpecifier::from_str(":all:")?], false),
|
||||
NoBuild::from_pip_args(vec![PackageNameSpecifier::from_str(":all:")?], false),
|
||||
NoBuild::All,
|
||||
);
|
||||
assert_eq!(
|
||||
NoBuild::from_args(vec![PackageNameSpecifier::from_str(":all:")?], true),
|
||||
NoBuild::from_pip_args(vec![PackageNameSpecifier::from_str(":all:")?], true),
|
||||
NoBuild::All,
|
||||
);
|
||||
assert_eq!(
|
||||
NoBuild::from_args(vec![PackageNameSpecifier::from_str(":none:")?], true),
|
||||
NoBuild::from_pip_args(vec![PackageNameSpecifier::from_str(":none:")?], true),
|
||||
NoBuild::All,
|
||||
);
|
||||
assert_eq!(
|
||||
NoBuild::from_args(vec![PackageNameSpecifier::from_str(":none:")?], false),
|
||||
NoBuild::from_pip_args(vec![PackageNameSpecifier::from_str(":none:")?], false),
|
||||
NoBuild::None,
|
||||
);
|
||||
assert_eq!(
|
||||
NoBuild::from_args(
|
||||
NoBuild::from_pip_args(
|
||||
vec![
|
||||
PackageNameSpecifier::from_str("foo")?,
|
||||
PackageNameSpecifier::from_str("bar")?
|
||||
|
@ -339,7 +377,7 @@ mod tests {
|
|||
]),
|
||||
);
|
||||
assert_eq!(
|
||||
NoBuild::from_args(
|
||||
NoBuild::from_pip_args(
|
||||
vec![
|
||||
PackageNameSpecifier::from_str("test")?,
|
||||
PackageNameSpecifier::All
|
||||
|
@ -349,7 +387,7 @@ mod tests {
|
|||
NoBuild::All,
|
||||
);
|
||||
assert_eq!(
|
||||
NoBuild::from_args(
|
||||
NoBuild::from_pip_args(
|
||||
vec![
|
||||
PackageNameSpecifier::from_str("foo")?,
|
||||
PackageNameSpecifier::from_str(":none:")?,
|
||||
|
|
|
@ -2,6 +2,9 @@ use std::str::FromStr;
|
|||
|
||||
use pep508_rs::PackageName;
|
||||
|
||||
/// A specifier used for (e.g.) pip's `--no-binary` flag.
|
||||
///
|
||||
/// This is a superset of the package name format, allowing for special values `:all:` and `:none:`.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PackageNameSpecifier {
|
||||
All,
|
||||
|
@ -85,10 +88,9 @@ impl schemars::JsonSchema for PackageNameSpecifier {
|
|||
}
|
||||
}
|
||||
|
||||
/// Package name specification.
|
||||
/// A repeated specifier used for (e.g.) pip's `--no-binary` flag.
|
||||
///
|
||||
/// Consumes both package names and selection directives for compatibility with pip flags
|
||||
/// such as `--no-binary`.
|
||||
/// This is a superset of the package name format, allowing for special values `:all:` and `:none:`.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PackageNameSpecifiers {
|
||||
All,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue