Remove unused methods from Resolution (#3754)

This commit is contained in:
Charlie Marsh 2024-05-22 14:48:44 -04:00 committed by GitHub
parent 0a87391d5d
commit fe28b2c278
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 11 additions and 24 deletions

1
Cargo.lock generated
View file

@ -1111,7 +1111,6 @@ dependencies = [
"platform-tags", "platform-tags",
"pypi-types", "pypi-types",
"rkyv", "rkyv",
"rustc-hash",
"schemars", "schemars",
"serde", "serde",
"serde_json", "serde_json",

View file

@ -30,7 +30,6 @@ indexmap = { workspace = true }
itertools = { workspace = true } itertools = { workspace = true }
once_cell = { workspace = true } once_cell = { workspace = true }
rkyv = { workspace = true } rkyv = { workspace = true }
rustc-hash = { workspace = true }
schemars = { workspace = true, optional = true } schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] } serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true } serde_json = { workspace = true }

View file

@ -1,4 +1,4 @@
use rustc_hash::FxHashMap; use std::collections::BTreeMap;
use pep508_rs::VerbatimUrl; use pep508_rs::VerbatimUrl;
use uv_normalize::PackageName; use uv_normalize::PackageName;
@ -10,19 +10,14 @@ use crate::{
/// A set of packages pinned at specific versions. /// A set of packages pinned at specific versions.
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Clone)]
pub struct Resolution(FxHashMap<PackageName, ResolvedDist>); pub struct Resolution(BTreeMap<PackageName, ResolvedDist>);
impl Resolution { impl Resolution {
/// Create a new resolution from the given pinned packages. /// Create a new resolution from the given pinned packages.
pub fn new(packages: FxHashMap<PackageName, ResolvedDist>) -> Self { pub fn new(packages: BTreeMap<PackageName, ResolvedDist>) -> Self {
Self(packages) Self(packages)
} }
/// Return the distribution for the given package name, if it exists.
pub fn get(&self, package_name: &PackageName) -> Option<&ResolvedDist> {
self.0.get(package_name)
}
/// Return the remote distribution for the given package name, if it exists. /// Return the remote distribution for the given package name, if it exists.
pub fn get_remote(&self, package_name: &PackageName) -> Option<&Dist> { pub fn get_remote(&self, package_name: &PackageName) -> Option<&Dist> {
match self.0.get(package_name) { match self.0.get(package_name) {
@ -44,11 +39,6 @@ impl Resolution {
self.0.values() self.0.values()
} }
/// Iterate over the [`ResolvedDist`] entities in this resolution.
pub fn into_distributions(self) -> impl Iterator<Item = ResolvedDist> {
self.0.into_values()
}
/// Return the number of distributions in this resolution. /// Return the number of distributions in this resolution.
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.0.len() self.0.len()
@ -60,10 +50,8 @@ impl Resolution {
} }
/// Return the set of [`Requirement`]s that this resolution represents. /// Return the set of [`Requirement`]s that this resolution represents.
pub fn requirements(&self) -> Vec<Requirement> { pub fn requirements(&self) -> impl Iterator<Item = Requirement> + '_ {
let mut requirements: Vec<_> = self.0.values().map(Requirement::from).collect(); self.0.values().map(Requirement::from)
requirements.sort_unstable_by(|a, b| a.name.cmp(&b.name));
requirements
} }
/// Return an iterator over the [`LocalEditable`] entities in this resolution. /// Return an iterator over the [`LocalEditable`] entities in this resolution.

View file

@ -192,12 +192,14 @@ impl<'a> BuildContext for BuildDispatch<'a> {
// Determine the set of installed packages. // Determine the set of installed packages.
let site_packages = SitePackages::from_executable(venv)?; let site_packages = SitePackages::from_executable(venv)?;
let requirements = resolution.requirements().collect::<Vec<_>>();
let Plan { let Plan {
cached, cached,
remote, remote,
reinstalls, reinstalls,
extraneous: _, extraneous: _,
} = Planner::with_requirements(&resolution.requirements()).build( } = Planner::with_requirements(&requirements).build(
site_packages, site_packages,
&Reinstall::None, &Reinstall::None,
&NoBinary::None, &NoBinary::None,

View file

@ -2,7 +2,7 @@
// as we build out universal locking. // as we build out universal locking.
#![allow(dead_code, unreachable_code, unused_variables)] #![allow(dead_code, unreachable_code, unused_variables)]
use std::collections::VecDeque; use std::collections::{BTreeMap, VecDeque};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::FromStr; use std::str::FromStr;
@ -71,7 +71,7 @@ impl Lock {
let mut queue: VecDeque<&Distribution> = VecDeque::new(); let mut queue: VecDeque<&Distribution> = VecDeque::new();
queue.push_back(root); queue.push_back(root);
let mut map = FxHashMap::default(); let mut map = BTreeMap::default();
while let Some(dist) = queue.pop_front() { while let Some(dist) = queue.pop_front() {
for dep in &dist.dependencies { for dep in &dist.dependencies {
let dep_dist = self.find_by_id(&dep.id); let dep_dist = self.find_by_id(&dep.id);

View file

@ -296,7 +296,6 @@ pub(crate) async fn install(
// despite not being explicitly requested. // despite not being explicitly requested.
let requirements = resolution let requirements = resolution
.requirements() .requirements()
.into_iter()
.filter(|requirement| { .filter(|requirement| {
if requirement.source.is_editable() { if requirement.source.is_editable() {
!editables !editables

View file

@ -285,7 +285,7 @@ pub(crate) async fn install(
) -> Result<(), Error> { ) -> Result<(), Error> {
let start = std::time::Instant::now(); let start = std::time::Instant::now();
let requirements = resolution.requirements(); let requirements = resolution.requirements().collect::<Vec<_>>();
// Partition into those that should be linked from the cache (`local`), those that need to be // Partition into those that should be linked from the cache (`local`), those that need to be
// downloaded (`remote`), and those that should be removed (`extraneous`). // downloaded (`remote`), and those that should be removed (`extraneous`).