mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Remove PubGrubPackage
dependency from ResolutionGraph
(#4168)
## Summary Similar to how we abstracted the dependencies into `ResolutionDependencyNames`, I think it makes sense to abstract the base packages into a `ResolutionPackage`. This also avoids leaking details about the various `PubGrubPackage` enum variants to `ResolutionGraph`.
This commit is contained in:
parent
18b40b0c7d
commit
72bc739a64
4 changed files with 173 additions and 182 deletions
|
@ -28,7 +28,7 @@ pub(crate) use locals::Locals;
|
|||
use pep440_rs::{Version, MIN_VERSION};
|
||||
use pep508_rs::{MarkerEnvironment, MarkerTree};
|
||||
use platform_tags::Tags;
|
||||
use pypi_types::{Metadata23, Requirement};
|
||||
use pypi_types::{Metadata23, Requirement, VerbatimParsedUrl};
|
||||
pub(crate) use urls::Urls;
|
||||
use uv_configuration::{Constraints, Overrides};
|
||||
use uv_distribution::{ArchiveMetadata, DistributionDatabase};
|
||||
|
@ -529,7 +529,7 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
|
|||
// that our resolver state is only cloned as much
|
||||
// as it needs to be. We basically move the state
|
||||
// into `forked_states`, and then only clone it if
|
||||
// there it at least one more fork to visit.
|
||||
// there is at least one more fork to visit.
|
||||
let mut cur_state = Some(state);
|
||||
let forks_len = forks.len();
|
||||
for (i, fork) in forks.into_iter().enumerate() {
|
||||
|
@ -1506,12 +1506,12 @@ struct SolveState {
|
|||
|
||||
impl SolveState {
|
||||
fn into_resolution(self) -> Resolution {
|
||||
let packages = self.pubgrub.partial_solution.extract_solution();
|
||||
let solution = self.pubgrub.partial_solution.extract_solution();
|
||||
let mut dependencies: FxHashMap<
|
||||
ResolutionDependencyNames,
|
||||
FxHashSet<ResolutionDependencyVersions>,
|
||||
> = FxHashMap::default();
|
||||
for (package, self_version) in &packages {
|
||||
for (package, self_version) in &solution {
|
||||
for id in &self.pubgrub.incompatibilities[package] {
|
||||
let pubgrub::solver::Kind::FromDependencyOf(
|
||||
ref self_package,
|
||||
|
@ -1528,7 +1528,7 @@ impl SolveState {
|
|||
if !self_range.contains(self_version) {
|
||||
continue;
|
||||
}
|
||||
let Some(dependency_version) = packages.get(dependency_package) else {
|
||||
let Some(dependency_version) = solution.get(dependency_package) else {
|
||||
continue;
|
||||
};
|
||||
if !dependency_range.contains(dependency_version) {
|
||||
|
@ -1649,10 +1649,33 @@ impl SolveState {
|
|||
}
|
||||
}
|
||||
}
|
||||
let packages = packages
|
||||
|
||||
let packages = solution
|
||||
.into_iter()
|
||||
.map(|(package, version)| (package, FxHashSet::from_iter([version])))
|
||||
.filter_map(|(package, version)| {
|
||||
if let PubGrubPackageInner::Package {
|
||||
name,
|
||||
extra,
|
||||
dev,
|
||||
url,
|
||||
marker: None,
|
||||
} = &*package
|
||||
{
|
||||
Some((
|
||||
ResolutionPackage {
|
||||
name: name.clone(),
|
||||
extra: extra.clone(),
|
||||
dev: dev.clone(),
|
||||
url: url.clone(),
|
||||
},
|
||||
FxHashSet::from_iter([version]),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
Resolution {
|
||||
packages,
|
||||
dependencies,
|
||||
|
@ -1663,12 +1686,20 @@ impl SolveState {
|
|||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct Resolution {
|
||||
pub(crate) packages: FxHashMap<PubGrubPackage, FxHashSet<Version>>,
|
||||
pub(crate) packages: FxHashMap<ResolutionPackage, FxHashSet<Version>>,
|
||||
pub(crate) dependencies:
|
||||
FxHashMap<ResolutionDependencyNames, FxHashSet<ResolutionDependencyVersions>>,
|
||||
pub(crate) pins: FilePins,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub(crate) struct ResolutionPackage {
|
||||
pub(crate) name: PackageName,
|
||||
pub(crate) extra: Option<ExtraName>,
|
||||
pub(crate) dev: Option<GroupName>,
|
||||
pub(crate) url: Option<VerbatimParsedUrl>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub(crate) struct ResolutionDependencyNames {
|
||||
pub(crate) from: PackageName,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue