mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
uv-resolver: slightly simplify ResolutionGraph::from_state
This changes the constructor to just take an `InMemoryIndex` directly instead of the constituent parts. No real reason other than it seems a little simpler.
This commit is contained in:
parent
6f76a66510
commit
9e977aa1be
2 changed files with 24 additions and 20 deletions
|
@ -1,5 +1,4 @@
|
|||
use std::hash::BuildHasherDefault;
|
||||
use std::sync::Arc;
|
||||
|
||||
use pubgrub::solver::{Kind, State};
|
||||
use pubgrub::type_aliases::SelectedDependencies;
|
||||
|
@ -19,7 +18,6 @@ use crate::preferences::Preferences;
|
|||
use crate::pubgrub::{PubGrubDistribution, PubGrubPackageInner};
|
||||
use crate::redirect::url_to_precise;
|
||||
use crate::resolution::AnnotatedDist;
|
||||
use crate::resolver::FxOnceMap;
|
||||
use crate::{
|
||||
lock, InMemoryIndex, Lock, LockError, Manifest, MetadataResponse, ResolveError,
|
||||
VersionsResponse,
|
||||
|
@ -39,10 +37,9 @@ impl ResolutionGraph {
|
|||
/// Create a new graph from the resolved PubGrub state.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn from_state(
|
||||
index: &InMemoryIndex,
|
||||
selection: &SelectedDependencies<UvDependencyProvider>,
|
||||
pins: &FilePins,
|
||||
packages: &FxOnceMap<PackageName, Arc<VersionsResponse>>,
|
||||
distributions: &FxOnceMap<VersionId, Arc<MetadataResponse>>,
|
||||
state: &State<UvDependencyProvider>,
|
||||
preferences: &Preferences,
|
||||
) -> anyhow::Result<Self, ResolveError> {
|
||||
|
@ -94,7 +91,7 @@ impl ResolutionGraph {
|
|||
.filter(|digests| !digests.is_empty())
|
||||
{
|
||||
digests.to_vec()
|
||||
} else if let Some(versions_response) = packages.get(name) {
|
||||
} else if let Some(versions_response) = index.packages().get(name) {
|
||||
if let VersionsResponse::Found(ref version_maps) = *versions_response {
|
||||
version_maps
|
||||
.iter()
|
||||
|
@ -115,12 +112,15 @@ impl ResolutionGraph {
|
|||
let metadata = {
|
||||
let dist = PubGrubDistribution::from_registry(name, version);
|
||||
|
||||
let response = distributions.get(&dist.version_id()).unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Every package should have metadata: {:?}",
|
||||
dist.version_id()
|
||||
)
|
||||
});
|
||||
let response = index
|
||||
.distributions()
|
||||
.get(&dist.version_id())
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Every package should have metadata: {:?}",
|
||||
dist.version_id()
|
||||
)
|
||||
});
|
||||
|
||||
let MetadataResponse::Found(archive) = &*response else {
|
||||
panic!(
|
||||
|
@ -168,7 +168,9 @@ impl ResolutionGraph {
|
|||
.filter(|digests| !digests.is_empty())
|
||||
{
|
||||
digests.to_vec()
|
||||
} else if let Some(metadata_response) = distributions.get(&dist.version_id()) {
|
||||
} else if let Some(metadata_response) =
|
||||
index.distributions().get(&dist.version_id())
|
||||
{
|
||||
if let MetadataResponse::Found(ref archive) = *metadata_response {
|
||||
let mut digests = archive.hashes.clone();
|
||||
digests.sort_unstable();
|
||||
|
@ -184,12 +186,15 @@ impl ResolutionGraph {
|
|||
let metadata = {
|
||||
let dist = PubGrubDistribution::from_url(name, url);
|
||||
|
||||
let response = distributions.get(&dist.version_id()).unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Every package should have metadata: {:?}",
|
||||
dist.version_id()
|
||||
)
|
||||
});
|
||||
let response = index
|
||||
.distributions()
|
||||
.get(&dist.version_id())
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Every package should have metadata: {:?}",
|
||||
dist.version_id()
|
||||
)
|
||||
});
|
||||
|
||||
let MetadataResponse::Found(archive) = &*response else {
|
||||
panic!(
|
||||
|
|
|
@ -337,10 +337,9 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
|
|||
}
|
||||
let selection = state.pubgrub.partial_solution.extract_solution();
|
||||
resolutions.push(ResolutionGraph::from_state(
|
||||
&self.index,
|
||||
&selection,
|
||||
&state.pins,
|
||||
self.index.packages(),
|
||||
self.index.distributions(),
|
||||
&state.pubgrub,
|
||||
&self.preferences,
|
||||
)?);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue