Remove `incompatibilities` from index (#905)

This isn't really part of the "index", it's part of the resolution.
This commit is contained in:
Charlie Marsh 2024-01-12 21:57:15 -05:00 committed by GitHub
parent 477186dcb3
commit 231686e71b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 15 deletions

16
Cargo.lock generated
View File

@ -752,6 +752,19 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "dashmap"
version = "5.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856"
dependencies = [
"cfg-if 1.0.0",
"hashbrown 0.14.3",
"lock_api",
"once_cell",
"parking_lot_core 0.9.9",
]
[[package]]
name = "data-encoding"
version = "2.5.0"
@ -2648,6 +2661,7 @@ dependencies = [
"cache-key",
"chrono",
"clap",
"dashmap 5.5.3",
"derivative",
"distribution-filename",
"distribution-types",
@ -4110,7 +4124,7 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28491611b6b9a0b9f027be139a4be792b13a20780100dd8b054d44dbf596d52b"
dependencies = [
"dashmap",
"dashmap 3.11.10",
"smallvec",
]

View File

@ -26,6 +26,7 @@ chrono = { version = "0.4.31" }
clap = { version = "4.4.13" }
configparser = { version = "3.0.4" }
csv = { version = "1.3.0" }
dashmap = { version = "5.5.3" }
data-encoding = { version = "2.5.0" }
derivative = { version = "2.2.0" }
directories = { version = "5.0.1" }

View File

@ -37,6 +37,7 @@ anyhow = { workspace = true }
bitflags = { workspace = true }
chrono = { workspace = true }
clap = { workspace = true, features = ["derive"], optional = true }
dashmap = { workspace = true }
derivative = { workspace = true }
fs-err = { workspace = true, features = ["tokio"] }
futures = { workspace = true }

View File

@ -1,7 +1,6 @@
use url::Url;
use distribution_types::PackageId;
use pep440_rs::VersionSpecifiers;
use puffin_normalize::PackageName;
use puffin_traits::OnceMap;
use pypi_types::Metadata21;
@ -18,9 +17,6 @@ pub(crate) struct Index {
/// A map from package ID to metadata for that distribution.
pub(crate) distributions: OnceMap<PackageId, Metadata21>,
/// A map from package ID to required Python version.
pub(crate) incompatibilities: OnceMap<PackageId, VersionSpecifiers>,
/// A map from source URL to precise URL.
pub(crate) redirects: OnceMap<Url, Url>,
}
@ -32,7 +28,6 @@ impl Index {
pub(crate) fn cancel_all(&self) {
self.packages.cancel_all();
self.distributions.cancel_all();
self.incompatibilities.cancel_all();
self.redirects.cancel_all();
}
}

View File

@ -3,6 +3,7 @@
use std::sync::Arc;
use anyhow::Result;
use dashmap::DashMap;
use futures::channel::mpsc::UnboundedReceiver;
use futures::{pin_mut, FutureExt, StreamExt};
use itertools::Itertools;
@ -17,9 +18,10 @@ use url::Url;
use distribution_filename::WheelFilename;
use distribution_types::{
BuiltDist, Dist, DistributionMetadata, LocalEditable, Name, RemoteSource, SourceDist,
VersionOrUrl,
BuiltDist, Dist, DistributionMetadata, LocalEditable, Name, PackageId, RemoteSource,
SourceDist, VersionOrUrl,
};
use pep440_rs::VersionSpecifiers;
use pep508_rs::{MarkerEnvironment, Requirement};
use platform_tags::Tags;
use puffin_client::RegistryClient;
@ -64,6 +66,7 @@ pub struct Resolver<'a, Provider: ResolverProvider> {
python_requirement: PythonRequirement<'a>,
selector: CandidateSelector,
index: Arc<Index>,
incompatibilities: DashMap<PackageId, VersionSpecifiers>,
editables: FxHashMap<PackageName, (LocalEditable, Metadata21)>,
reporter: Option<Arc<dyn Reporter>>,
provider: Provider,
@ -155,6 +158,7 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
Self {
index: Arc::new(index),
incompatibilities: DashMap::default(),
selector,
allowed_urls,
project: manifest.project,
@ -492,9 +496,8 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
// If the version is incompatible, short-circuit.
if let Some(requires_python) = candidate.validate(&self.python_requirement) {
self.index
.incompatibilities
.done(candidate.package_id(), requires_python.clone());
self.incompatibilities
.insert(candidate.package_id(), requires_python.clone());
return Ok(Some(candidate.version().clone()));
}
@ -606,7 +609,7 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
// If the package is known to be incompatible, return the Python version as an
// incompatibility, and skip fetching the metadata.
if let Some(entry) = self.index.incompatibilities.get(&package_id) {
if let Some(entry) = self.incompatibilities.get(&package_id) {
let requires_python = entry.value();
let version = requires_python
.iter()
@ -765,9 +768,8 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
// If the version is incompatible, short-circuit.
if let Some(requires_python) = candidate.validate(&self.python_requirement) {
self.index
.incompatibilities
.done(candidate.package_id(), requires_python.clone());
self.incompatibilities
.insert(candidate.package_id(), requires_python.clone());
return Ok(None);
}