Refactor incompatiblity tracking for distributions (#1298)

Extends the "compatibility" types introduced in #1293 to apply to source
distributions as well as wheels.

- We now track the most-relevant incompatible source distribution
- Exclude newer, Python requirements, and yanked versions are all
tracked as incompatibilities in the new model (this lets us remove
`DistMetadata`!)
This commit is contained in:
Zanie Blue 2024-03-08 11:02:31 -06:00 committed by GitHub
parent 1181aa9be4
commit 10c4effbd3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 498 additions and 343 deletions

View file

@ -8,8 +8,8 @@ use crate::Manifest;
/// A set of package versions that are permitted, even if they're marked as yanked by the
/// relevant index.
#[derive(Debug, Default)]
pub(crate) struct AllowedYanks(FxHashMap<PackageName, FxHashSet<Version>>);
#[derive(Debug, Default, Clone)]
pub struct AllowedYanks(FxHashMap<PackageName, FxHashSet<Version>>);
impl AllowedYanks {
pub(crate) fn from_manifest(manifest: &Manifest, markers: &MarkerEnvironment) -> Self {
@ -49,11 +49,12 @@ impl AllowedYanks {
Self(allowed_yanks)
}
/// Returns `true` if the given package version is allowed, even if it's marked as yanked by
/// the relevant index.
pub(crate) fn allowed(&self, package_name: &PackageName, version: &Version) -> bool {
self.0
.get(package_name)
.is_some_and(|allowed_yanks| allowed_yanks.contains(version))
/// Returns versions for the given package which are allowed even if marked as yanked by the
/// relevant index.
pub(crate) fn allowed_versions(
&self,
package_name: &PackageName,
) -> Option<&FxHashSet<Version>> {
self.0.get(package_name)
}
}