Use common routines for pip install and pip sync (#3737)

## Summary

This PR takes the functions used in `pip install`, moves them into a
common module, and then replaces all the `pip sync` logic with calls
into those functions. The net effect is that `pip install` and `pip
sync` share far more code and demonstrate much more consistent behavior.

Closes https://github.com/astral-sh/uv/issues/3555.
This commit is contained in:
Charlie Marsh 2024-05-22 12:15:17 -04:00 committed by GitHub
parent b8ef436c42
commit 0313e7d78b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 1078 additions and 1031 deletions

View file

@ -205,4 +205,9 @@ impl RequirementSource {
},
}
}
/// Returns `true` if the source is editable.
pub fn is_editable(&self) -> bool {
matches!(self, Self::Path { editable: true, .. })
}
}

View file

@ -59,16 +59,9 @@ impl Resolution {
self.0.is_empty()
}
/// Return the set of [`Requirement`]s that this resolution represents, exclusive of any
/// editable requirements.
/// Return the set of [`Requirement`]s that this resolution represents.
pub fn requirements(&self) -> Vec<Requirement> {
let mut requirements: Vec<_> = self
.0
.values()
// Remove editable requirements
.filter(|dist| !dist.is_editable())
.map(Requirement::from)
.collect();
let mut requirements: Vec<_> = self.0.values().map(Requirement::from).collect();
requirements.sort_unstable_by(|a, b| a.name.cmp(&b.name));
requirements
}