mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-02 12:59:45 +00:00
Avoid double-resolving during pip-install (#610)
## Summary At present, when performing a `pip-install`, we first do a resolution, then take the set of requirements and basically run them through our `pip-sync`, which itself includes re-resolving the dependencies to get a specific `Dist` for each package. (E.g., the set of requirements might say `flask==3.0.0`, but the installer needs a specific _wheel_ or source distribution to install.) This PR removes this second resolution by exposing the set of pinned packages from the resolution. The main challenge here is that we have an optimization in the resolver such that we let the resolver read metadata from an incompatible wheel as long as a source distribution exists for a given package. This lets us avoid building source distributions in the resolver under the assumption that we'll be able to install the package later on, if needed. As such, the resolver now needs to track the resolution and installation filenames separately.
This commit is contained in:
parent
a0b3815d84
commit
c764155988
8 changed files with 289 additions and 192 deletions
30
crates/puffin-resolver/src/pins.rs
Normal file
30
crates/puffin-resolver/src/pins.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use crate::candidate_selector::Candidate;
|
||||
use puffin_normalize::PackageName;
|
||||
use pypi_types::{File, IndexUrl};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
/// A set of package versions pinned to specific files.
|
||||
///
|
||||
/// For example, given `Flask==3.0.0`, the [`FilePins`] would contain a mapping from `Flask` to
|
||||
/// `3.0.0` to the specific wheel or source distribution archive that was pinned for that version.
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct FilePins(FxHashMap<PackageName, FxHashMap<pep440_rs::Version, (IndexUrl, File)>>);
|
||||
|
||||
impl FilePins {
|
||||
/// Pin a candidate package.
|
||||
pub(crate) fn insert(&mut self, candidate: &Candidate, index: &IndexUrl) {
|
||||
self.0.entry(candidate.name().clone()).or_default().insert(
|
||||
candidate.version().clone().into(),
|
||||
(index.clone(), candidate.install().clone().into()),
|
||||
);
|
||||
}
|
||||
|
||||
/// Return the pinned file for the given package name and version, if it exists.
|
||||
pub(crate) fn get(
|
||||
&self,
|
||||
name: &PackageName,
|
||||
version: &pep440_rs::Version,
|
||||
) -> Option<&(IndexUrl, File)> {
|
||||
self.0.get(name)?.get(version)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue