Skip to content

Commit

Permalink
Remove unused methods from Resolution (#3754)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored May 22, 2024
1 parent 0a87391 commit fe28b2c
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 24 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/distribution-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ indexmap = { workspace = true }
itertools = { workspace = true }
once_cell = { workspace = true }
rkyv = { workspace = true }
rustc-hash = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
Expand Down
22 changes: 5 additions & 17 deletions crates/distribution-types/src/resolution.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_hash::FxHashMap;
use std::collections::BTreeMap;

use pep508_rs::VerbatimUrl;
use uv_normalize::PackageName;
Expand All @@ -10,19 +10,14 @@ use crate::{

/// A set of packages pinned at specific versions.
#[derive(Debug, Default, Clone)]
pub struct Resolution(FxHashMap<PackageName, ResolvedDist>);
pub struct Resolution(BTreeMap<PackageName, ResolvedDist>);

impl Resolution {
/// 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)
}

/// 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.
pub fn get_remote(&self, package_name: &PackageName) -> Option<&Dist> {
match self.0.get(package_name) {
Expand All @@ -44,11 +39,6 @@ impl Resolution {
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.
pub fn len(&self) -> usize {
self.0.len()
Expand All @@ -60,10 +50,8 @@ impl Resolution {
}

/// Return the set of [`Requirement`]s that this resolution represents.
pub fn requirements(&self) -> Vec<Requirement> {
let mut requirements: Vec<_> = self.0.values().map(Requirement::from).collect();
requirements.sort_unstable_by(|a, b| a.name.cmp(&b.name));
requirements
pub fn requirements(&self) -> impl Iterator<Item = Requirement> + '_ {
self.0.values().map(Requirement::from)
}

/// Return an iterator over the [`LocalEditable`] entities in this resolution.
Expand Down
4 changes: 3 additions & 1 deletion crates/uv-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,14 @@ impl<'a> BuildContext for BuildDispatch<'a> {
// Determine the set of installed packages.
let site_packages = SitePackages::from_executable(venv)?;

let requirements = resolution.requirements().collect::<Vec<_>>();

let Plan {
cached,
remote,
reinstalls,
extraneous: _,
} = Planner::with_requirements(&resolution.requirements()).build(
} = Planner::with_requirements(&requirements).build(
site_packages,
&Reinstall::None,
&NoBinary::None,
Expand Down
4 changes: 2 additions & 2 deletions crates/uv-resolver/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// as we build out universal locking.
#![allow(dead_code, unreachable_code, unused_variables)]

use std::collections::VecDeque;
use std::collections::{BTreeMap, VecDeque};
use std::path::{Path, PathBuf};
use std::str::FromStr;

Expand Down Expand Up @@ -71,7 +71,7 @@ impl Lock {
let mut queue: VecDeque<&Distribution> = VecDeque::new();
queue.push_back(root);

let mut map = FxHashMap::default();
let mut map = BTreeMap::default();
while let Some(dist) = queue.pop_front() {
for dep in &dist.dependencies {
let dep_dist = self.find_by_id(&dep.id);
Expand Down
1 change: 0 additions & 1 deletion crates/uv/src/commands/pip/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ pub(crate) async fn install(
// despite not being explicitly requested.
let requirements = resolution
.requirements()
.into_iter()
.filter(|requirement| {
if requirement.source.is_editable() {
!editables
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ pub(crate) async fn install(
) -> Result<(), Error> {
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
// downloaded (`remote`), and those that should be removed (`extraneous`).
Expand Down

0 comments on commit fe28b2c

Please sign in to comment.