Support {package}@{version} in uv tool install (#6762)

## Summary

Closes https://github.com/astral-sh/uv/issues/6759.

Closes https://github.com/astral-sh/uv/issues/6535.
This commit is contained in:
Charlie Marsh 2024-08-28 12:40:49 -04:00 committed by GitHub
parent af323888ee
commit cef3d35405
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 505 additions and 159 deletions

View file

@ -74,7 +74,7 @@ pub enum Upgrade {
}
impl Upgrade {
/// Determine the upgrade strategy from the command-line arguments.
/// Determine the [`Upgrade`] strategy from the command-line arguments.
pub fn from_args(upgrade: Option<bool>, upgrade_package: Vec<Requirement>) -> Self {
match upgrade {
Some(true) => Self::All,
@ -97,6 +97,15 @@ impl Upgrade {
}
}
/// Create an [`Upgrade`] strategy to upgrade a single package.
pub fn package(package_name: PackageName) -> Self {
Self::Packages({
let mut map = FxHashMap::default();
map.insert(package_name, vec![]);
map
})
}
/// Returns `true` if no packages should be upgraded.
pub fn is_none(&self) -> bool {
matches!(self, Self::None)
@ -130,6 +139,25 @@ impl Upgrade {
Either::Left(std::iter::empty())
}
}
/// Combine a set of [`Upgrade`] values.
#[must_use]
pub fn combine(self, other: Self) -> Self {
match (self, other) {
// If both are `None`, the result is `None`.
(Self::None, Self::None) => Self::None,
// If either is `All`, the result is `All`.
(Self::All, _) | (_, Self::All) => Self::All,
// If one is `None`, the result is the other.
(Self::Packages(a), Self::None) => Self::Packages(a),
(Self::None, Self::Packages(b)) => Self::Packages(b),
// If both are `Packages`, the result is the union of the two.
(Self::Packages(mut a), Self::Packages(b)) => {
a.extend(b);
Self::Packages(a)
}
}
}
}
/// Create a [`Refresh`] policy by integrating the [`Upgrade`] policy.