mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-26 20:19:08 +00:00
Move FlatIndex
into the uv-resolver
crate (#2972)
## Summary This lets us remove circular dependencies (in the future, e.g., #2945) that arise from `FlatIndex` needing a bunch of resolver-specific abstractions (like incompatibilities, required hashes, etc.) that aren't necessary to _fetch_ the flat index entries.
This commit is contained in:
parent
a9d554fa90
commit
48ba7df98a
18 changed files with 222 additions and 216 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4399,7 +4399,6 @@ dependencies = [
|
||||||
"reqwest-retry",
|
"reqwest-retry",
|
||||||
"rkyv",
|
"rkyv",
|
||||||
"rmp-serde",
|
"rmp-serde",
|
||||||
"rustc-hash",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sys-info",
|
"sys-info",
|
||||||
|
|
|
@ -34,7 +34,6 @@ reqwest-middleware = { workspace = true }
|
||||||
reqwest-retry = { workspace = true }
|
reqwest-retry = { workspace = true }
|
||||||
rkyv = { workspace = true }
|
rkyv = { workspace = true }
|
||||||
rmp-serde = { workspace = true }
|
rmp-serde = { workspace = true }
|
||||||
rustc-hash = { workspace = true }
|
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
sys-info = { workspace = true }
|
sys-info = { workspace = true }
|
||||||
|
|
|
@ -1,26 +1,17 @@
|
||||||
use std::collections::btree_map::Entry;
|
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use futures::{FutureExt, StreamExt};
|
use futures::{FutureExt, StreamExt};
|
||||||
use reqwest::Response;
|
use reqwest::Response;
|
||||||
use rustc_hash::FxHashMap;
|
|
||||||
use tracing::{debug, info_span, instrument, warn, Instrument};
|
use tracing::{debug, info_span, warn, Instrument};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use distribution_filename::{DistFilename, SourceDistFilename, WheelFilename};
|
use distribution_filename::DistFilename;
|
||||||
use distribution_types::{
|
use distribution_types::{File, FileLocation, FlatIndexLocation, IndexUrl};
|
||||||
BuiltDist, Dist, File, FileLocation, FlatIndexLocation, IncompatibleSource, IncompatibleWheel,
|
|
||||||
IndexUrl, PrioritizedDist, RegistryBuiltDist, RegistrySourceDist, SourceDist,
|
|
||||||
SourceDistCompatibility, WheelCompatibility,
|
|
||||||
};
|
|
||||||
use pep440_rs::Version;
|
|
||||||
use pep508_rs::VerbatimUrl;
|
use pep508_rs::VerbatimUrl;
|
||||||
use platform_tags::Tags;
|
|
||||||
|
|
||||||
use uv_cache::{Cache, CacheBucket};
|
use uv_cache::{Cache, CacheBucket};
|
||||||
use uv_configuration::{NoBinary, NoBuild};
|
|
||||||
use uv_normalize::PackageName;
|
|
||||||
|
|
||||||
use crate::cached_client::{CacheControl, CachedClientError};
|
use crate::cached_client::{CacheControl, CachedClientError};
|
||||||
use crate::html::SimpleHtml;
|
use crate::html::SimpleHtml;
|
||||||
|
@ -38,10 +29,10 @@ pub enum FlatIndexError {
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct FlatIndexEntries {
|
pub struct FlatIndexEntries {
|
||||||
/// The list of `--find-links` entries.
|
/// The list of `--find-links` entries.
|
||||||
entries: Vec<(DistFilename, File, IndexUrl)>,
|
pub entries: Vec<(DistFilename, File, IndexUrl)>,
|
||||||
/// Whether any `--find-links` entries could not be resolved due to a lack of network
|
/// Whether any `--find-links` entries could not be resolved due to a lack of network
|
||||||
/// connectivity.
|
/// connectivity.
|
||||||
offline: bool,
|
pub offline: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FlatIndexEntries {
|
impl FlatIndexEntries {
|
||||||
|
@ -258,172 +249,3 @@ impl<'a> FlatIndexClient<'a> {
|
||||||
Ok(FlatIndexEntries::from_entries(dists))
|
Ok(FlatIndexEntries::from_entries(dists))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of [`PrioritizedDist`] from a `--find-links` entry, indexed by [`PackageName`]
|
|
||||||
/// and [`Version`].
|
|
||||||
#[derive(Debug, Clone, Default)]
|
|
||||||
pub struct FlatIndex {
|
|
||||||
/// The list of [`FlatDistributions`] from the `--find-links` entries, indexed by package name.
|
|
||||||
index: FxHashMap<PackageName, FlatDistributions>,
|
|
||||||
/// Whether any `--find-links` entries could not be resolved due to a lack of network
|
|
||||||
/// connectivity.
|
|
||||||
offline: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FlatIndex {
|
|
||||||
/// Collect all files from a `--find-links` target into a [`FlatIndex`].
|
|
||||||
#[instrument(skip_all)]
|
|
||||||
pub fn from_entries(
|
|
||||||
entries: FlatIndexEntries,
|
|
||||||
tags: &Tags,
|
|
||||||
no_build: &NoBuild,
|
|
||||||
no_binary: &NoBinary,
|
|
||||||
) -> Self {
|
|
||||||
// Collect compatible distributions.
|
|
||||||
let mut index = FxHashMap::default();
|
|
||||||
for (filename, file, url) in entries.entries {
|
|
||||||
let distributions = index.entry(filename.name().clone()).or_default();
|
|
||||||
Self::add_file(
|
|
||||||
distributions,
|
|
||||||
file,
|
|
||||||
filename,
|
|
||||||
tags,
|
|
||||||
no_build,
|
|
||||||
no_binary,
|
|
||||||
url,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect offline entries.
|
|
||||||
let offline = entries.offline;
|
|
||||||
|
|
||||||
Self { index, offline }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_file(
|
|
||||||
distributions: &mut FlatDistributions,
|
|
||||||
file: File,
|
|
||||||
filename: DistFilename,
|
|
||||||
tags: &Tags,
|
|
||||||
no_build: &NoBuild,
|
|
||||||
no_binary: &NoBinary,
|
|
||||||
index: IndexUrl,
|
|
||||||
) {
|
|
||||||
// No `requires-python` here: for source distributions, we don't have that information;
|
|
||||||
// for wheels, we read it lazily only when selected.
|
|
||||||
match filename {
|
|
||||||
DistFilename::WheelFilename(filename) => {
|
|
||||||
let version = filename.version.clone();
|
|
||||||
|
|
||||||
let compatibility = Self::wheel_compatibility(&filename, tags, no_binary);
|
|
||||||
let dist = Dist::Built(BuiltDist::Registry(RegistryBuiltDist {
|
|
||||||
filename,
|
|
||||||
file: Box::new(file),
|
|
||||||
index,
|
|
||||||
}));
|
|
||||||
match distributions.0.entry(version) {
|
|
||||||
Entry::Occupied(mut entry) => {
|
|
||||||
entry.get_mut().insert_built(dist, vec![], compatibility);
|
|
||||||
}
|
|
||||||
Entry::Vacant(entry) => {
|
|
||||||
entry.insert(PrioritizedDist::from_built(dist, vec![], compatibility));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DistFilename::SourceDistFilename(filename) => {
|
|
||||||
let compatibility = Self::source_dist_compatibility(&filename, no_build);
|
|
||||||
let dist = Dist::Source(SourceDist::Registry(RegistrySourceDist {
|
|
||||||
filename: filename.clone(),
|
|
||||||
file: Box::new(file),
|
|
||||||
index,
|
|
||||||
}));
|
|
||||||
match distributions.0.entry(filename.version) {
|
|
||||||
Entry::Occupied(mut entry) => {
|
|
||||||
entry.get_mut().insert_source(dist, vec![], compatibility);
|
|
||||||
}
|
|
||||||
Entry::Vacant(entry) => {
|
|
||||||
entry.insert(PrioritizedDist::from_source(dist, vec![], compatibility));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn source_dist_compatibility(
|
|
||||||
filename: &SourceDistFilename,
|
|
||||||
no_build: &NoBuild,
|
|
||||||
) -> SourceDistCompatibility {
|
|
||||||
// Check if source distributions are allowed for this package.
|
|
||||||
let no_build = match no_build {
|
|
||||||
NoBuild::None => false,
|
|
||||||
NoBuild::All => true,
|
|
||||||
NoBuild::Packages(packages) => packages.contains(&filename.name),
|
|
||||||
};
|
|
||||||
|
|
||||||
if no_build {
|
|
||||||
return SourceDistCompatibility::Incompatible(IncompatibleSource::NoBuild);
|
|
||||||
}
|
|
||||||
|
|
||||||
SourceDistCompatibility::Compatible
|
|
||||||
}
|
|
||||||
|
|
||||||
fn wheel_compatibility(
|
|
||||||
filename: &WheelFilename,
|
|
||||||
tags: &Tags,
|
|
||||||
no_binary: &NoBinary,
|
|
||||||
) -> WheelCompatibility {
|
|
||||||
// Check if binaries are allowed for this package.
|
|
||||||
let no_binary = match no_binary {
|
|
||||||
NoBinary::None => false,
|
|
||||||
NoBinary::All => true,
|
|
||||||
NoBinary::Packages(packages) => packages.contains(&filename.name),
|
|
||||||
};
|
|
||||||
|
|
||||||
if no_binary {
|
|
||||||
return WheelCompatibility::Incompatible(IncompatibleWheel::NoBinary);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine a compatibility for the wheel based on tags.
|
|
||||||
WheelCompatibility::from(filename.compatibility(tags))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the [`FlatDistributions`] for the given package name.
|
|
||||||
pub fn get(&self, package_name: &PackageName) -> Option<&FlatDistributions> {
|
|
||||||
self.index.get(package_name)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if there are any offline `--find-links` entries.
|
|
||||||
pub fn offline(&self) -> bool {
|
|
||||||
self.offline
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A set of [`PrioritizedDist`] from a `--find-links` entry for a single package, indexed
|
|
||||||
/// by [`Version`].
|
|
||||||
#[derive(Debug, Clone, Default)]
|
|
||||||
pub struct FlatDistributions(BTreeMap<Version, PrioritizedDist>);
|
|
||||||
|
|
||||||
impl FlatDistributions {
|
|
||||||
pub fn iter(&self) -> impl Iterator<Item = (&Version, &PrioritizedDist)> {
|
|
||||||
self.0.iter()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn remove(&mut self, version: &Version) -> Option<PrioritizedDist> {
|
|
||||||
self.0.remove(version)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoIterator for FlatDistributions {
|
|
||||||
type Item = (Version, PrioritizedDist);
|
|
||||||
type IntoIter = std::collections::btree_map::IntoIter<Version, PrioritizedDist>;
|
|
||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
|
||||||
self.0.into_iter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<FlatDistributions> for BTreeMap<Version, PrioritizedDist> {
|
|
||||||
fn from(distributions: FlatDistributions) -> Self {
|
|
||||||
distributions.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
pub use base_client::{BaseClient, BaseClientBuilder};
|
pub use base_client::{BaseClient, BaseClientBuilder};
|
||||||
pub use cached_client::{CacheControl, CachedClient, CachedClientError, DataWithCachePolicy};
|
pub use cached_client::{CacheControl, CachedClient, CachedClientError, DataWithCachePolicy};
|
||||||
pub use error::{BetterReqwestError, Error, ErrorKind};
|
pub use error::{BetterReqwestError, Error, ErrorKind};
|
||||||
pub use flat_index::{FlatDistributions, FlatIndex, FlatIndexClient, FlatIndexError};
|
pub use flat_index::{FlatIndexClient, FlatIndexEntries, FlatIndexError};
|
||||||
pub use linehaul::LineHaul;
|
pub use linehaul::LineHaul;
|
||||||
pub use registry_client::{
|
pub use registry_client::{
|
||||||
Connectivity, RegistryClient, RegistryClientBuilder, SimpleMetadata, SimpleMetadatum,
|
Connectivity, RegistryClient, RegistryClientBuilder, SimpleMetadata, SimpleMetadatum,
|
||||||
|
|
|
@ -9,11 +9,11 @@ use distribution_types::IndexLocations;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use uv_build::{SourceBuild, SourceBuildContext};
|
use uv_build::{SourceBuild, SourceBuildContext};
|
||||||
use uv_cache::{Cache, CacheArgs};
|
use uv_cache::{Cache, CacheArgs};
|
||||||
use uv_client::{FlatIndex, RegistryClientBuilder};
|
use uv_client::RegistryClientBuilder;
|
||||||
use uv_configuration::{BuildKind, ConfigSettings, NoBinary, NoBuild, SetupPyStrategy};
|
use uv_configuration::{BuildKind, ConfigSettings, NoBinary, NoBuild, SetupPyStrategy};
|
||||||
use uv_dispatch::BuildDispatch;
|
use uv_dispatch::BuildDispatch;
|
||||||
use uv_interpreter::PythonEnvironment;
|
use uv_interpreter::PythonEnvironment;
|
||||||
use uv_resolver::InMemoryIndex;
|
use uv_resolver::{FlatIndex, InMemoryIndex};
|
||||||
use uv_types::{BuildContext, BuildIsolation, InFlight};
|
use uv_types::{BuildContext, BuildIsolation, InFlight};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
|
|
@ -12,12 +12,12 @@ use petgraph::dot::{Config as DotConfig, Dot};
|
||||||
use distribution_types::{FlatIndexLocation, IndexLocations, IndexUrl, Resolution};
|
use distribution_types::{FlatIndexLocation, IndexLocations, IndexUrl, Resolution};
|
||||||
use pep508_rs::Requirement;
|
use pep508_rs::Requirement;
|
||||||
use uv_cache::{Cache, CacheArgs};
|
use uv_cache::{Cache, CacheArgs};
|
||||||
use uv_client::{FlatIndex, FlatIndexClient, RegistryClientBuilder};
|
use uv_client::{FlatIndexClient, RegistryClientBuilder};
|
||||||
use uv_configuration::{ConfigSettings, NoBinary, NoBuild, SetupPyStrategy};
|
use uv_configuration::{ConfigSettings, NoBinary, NoBuild, SetupPyStrategy};
|
||||||
use uv_dispatch::BuildDispatch;
|
use uv_dispatch::BuildDispatch;
|
||||||
use uv_installer::SitePackages;
|
use uv_installer::SitePackages;
|
||||||
use uv_interpreter::PythonEnvironment;
|
use uv_interpreter::PythonEnvironment;
|
||||||
use uv_resolver::{InMemoryIndex, Manifest, Options, Resolver};
|
use uv_resolver::{FlatIndex, InMemoryIndex, Manifest, Options, Resolver};
|
||||||
use uv_types::{BuildIsolation, InFlight};
|
use uv_types::{BuildIsolation, InFlight};
|
||||||
|
|
||||||
#[derive(ValueEnum, Default, Clone)]
|
#[derive(ValueEnum, Default, Clone)]
|
||||||
|
|
|
@ -14,12 +14,12 @@ use distribution_types::IndexLocations;
|
||||||
use pep440_rs::{Version, VersionSpecifier, VersionSpecifiers};
|
use pep440_rs::{Version, VersionSpecifier, VersionSpecifiers};
|
||||||
use pep508_rs::{Requirement, VersionOrUrl};
|
use pep508_rs::{Requirement, VersionOrUrl};
|
||||||
use uv_cache::{Cache, CacheArgs};
|
use uv_cache::{Cache, CacheArgs};
|
||||||
use uv_client::{FlatIndex, OwnedArchive, RegistryClient, RegistryClientBuilder};
|
use uv_client::{OwnedArchive, RegistryClient, RegistryClientBuilder};
|
||||||
use uv_configuration::{ConfigSettings, NoBinary, NoBuild, SetupPyStrategy};
|
use uv_configuration::{ConfigSettings, NoBinary, NoBuild, SetupPyStrategy};
|
||||||
use uv_dispatch::BuildDispatch;
|
use uv_dispatch::BuildDispatch;
|
||||||
use uv_interpreter::PythonEnvironment;
|
use uv_interpreter::PythonEnvironment;
|
||||||
use uv_normalize::PackageName;
|
use uv_normalize::PackageName;
|
||||||
use uv_resolver::InMemoryIndex;
|
use uv_resolver::{FlatIndex, InMemoryIndex};
|
||||||
use uv_types::{BuildContext, BuildIsolation, InFlight};
|
use uv_types::{BuildContext, BuildIsolation, InFlight};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
|
|
@ -16,11 +16,11 @@ use distribution_types::{IndexLocations, Name, Resolution, SourceDist};
|
||||||
use pep508_rs::Requirement;
|
use pep508_rs::Requirement;
|
||||||
use uv_build::{SourceBuild, SourceBuildContext};
|
use uv_build::{SourceBuild, SourceBuildContext};
|
||||||
use uv_cache::Cache;
|
use uv_cache::Cache;
|
||||||
use uv_client::{FlatIndex, RegistryClient};
|
use uv_client::RegistryClient;
|
||||||
use uv_configuration::{BuildKind, ConfigSettings, NoBinary, NoBuild, Reinstall, SetupPyStrategy};
|
use uv_configuration::{BuildKind, ConfigSettings, NoBinary, NoBuild, Reinstall, SetupPyStrategy};
|
||||||
use uv_installer::{Downloader, Installer, Plan, Planner, SitePackages};
|
use uv_installer::{Downloader, Installer, Plan, Planner, SitePackages};
|
||||||
use uv_interpreter::{Interpreter, PythonEnvironment};
|
use uv_interpreter::{Interpreter, PythonEnvironment};
|
||||||
use uv_resolver::{InMemoryIndex, Manifest, Options, Resolver};
|
use uv_resolver::{FlatIndex, InMemoryIndex, Manifest, Options, Resolver};
|
||||||
use uv_types::{BuildContext, BuildIsolation, EmptyInstalledPackages, InFlight};
|
use uv_types::{BuildContext, BuildIsolation, EmptyInstalledPackages, InFlight};
|
||||||
|
|
||||||
/// The main implementation of [`BuildContext`], used by the CLI, see [`BuildContext`]
|
/// The main implementation of [`BuildContext`], used by the CLI, see [`BuildContext`]
|
||||||
|
|
185
crates/uv-resolver/src/flat_index.rs
Normal file
185
crates/uv-resolver/src/flat_index.rs
Normal file
|
@ -0,0 +1,185 @@
|
||||||
|
use std::collections::btree_map::Entry;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
|
use distribution_filename::{DistFilename, SourceDistFilename, WheelFilename};
|
||||||
|
use distribution_types::{
|
||||||
|
BuiltDist, Dist, File, IncompatibleSource, IncompatibleWheel, IndexUrl, PrioritizedDist,
|
||||||
|
RegistryBuiltDist, RegistrySourceDist, SourceDist, SourceDistCompatibility, WheelCompatibility,
|
||||||
|
};
|
||||||
|
use pep440_rs::Version;
|
||||||
|
use platform_tags::Tags;
|
||||||
|
use uv_client::FlatIndexEntries;
|
||||||
|
use uv_configuration::{NoBinary, NoBuild};
|
||||||
|
use uv_normalize::PackageName;
|
||||||
|
|
||||||
|
/// A set of [`PrioritizedDist`] from a `--find-links` entry, indexed by [`PackageName`]
|
||||||
|
/// and [`Version`].
|
||||||
|
#[derive(Debug, Clone, Default)]
|
||||||
|
pub struct FlatIndex {
|
||||||
|
/// The list of [`FlatDistributions`] from the `--find-links` entries, indexed by package name.
|
||||||
|
index: FxHashMap<PackageName, FlatDistributions>,
|
||||||
|
/// Whether any `--find-links` entries could not be resolved due to a lack of network
|
||||||
|
/// connectivity.
|
||||||
|
offline: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FlatIndex {
|
||||||
|
/// Collect all files from a `--find-links` target into a [`FlatIndex`].
|
||||||
|
#[instrument(skip_all)]
|
||||||
|
pub fn from_entries(
|
||||||
|
entries: FlatIndexEntries,
|
||||||
|
tags: &Tags,
|
||||||
|
no_build: &NoBuild,
|
||||||
|
no_binary: &NoBinary,
|
||||||
|
) -> Self {
|
||||||
|
// Collect compatible distributions.
|
||||||
|
let mut index = FxHashMap::default();
|
||||||
|
for (filename, file, url) in entries.entries {
|
||||||
|
let distributions = index.entry(filename.name().clone()).or_default();
|
||||||
|
Self::add_file(
|
||||||
|
distributions,
|
||||||
|
file,
|
||||||
|
filename,
|
||||||
|
tags,
|
||||||
|
no_build,
|
||||||
|
no_binary,
|
||||||
|
url,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect offline entries.
|
||||||
|
let offline = entries.offline;
|
||||||
|
|
||||||
|
Self { index, offline }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_file(
|
||||||
|
distributions: &mut FlatDistributions,
|
||||||
|
file: File,
|
||||||
|
filename: DistFilename,
|
||||||
|
tags: &Tags,
|
||||||
|
no_build: &NoBuild,
|
||||||
|
no_binary: &NoBinary,
|
||||||
|
index: IndexUrl,
|
||||||
|
) {
|
||||||
|
// No `requires-python` here: for source distributions, we don't have that information;
|
||||||
|
// for wheels, we read it lazily only when selected.
|
||||||
|
match filename {
|
||||||
|
DistFilename::WheelFilename(filename) => {
|
||||||
|
let version = filename.version.clone();
|
||||||
|
|
||||||
|
let compatibility = Self::wheel_compatibility(&filename, tags, no_binary);
|
||||||
|
let dist = Dist::Built(BuiltDist::Registry(RegistryBuiltDist {
|
||||||
|
filename,
|
||||||
|
file: Box::new(file),
|
||||||
|
index,
|
||||||
|
}));
|
||||||
|
match distributions.0.entry(version) {
|
||||||
|
Entry::Occupied(mut entry) => {
|
||||||
|
entry.get_mut().insert_built(dist, vec![], compatibility);
|
||||||
|
}
|
||||||
|
Entry::Vacant(entry) => {
|
||||||
|
entry.insert(PrioritizedDist::from_built(dist, vec![], compatibility));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DistFilename::SourceDistFilename(filename) => {
|
||||||
|
let compatibility = Self::source_dist_compatibility(&filename, no_build);
|
||||||
|
let dist = Dist::Source(SourceDist::Registry(RegistrySourceDist {
|
||||||
|
filename: filename.clone(),
|
||||||
|
file: Box::new(file),
|
||||||
|
index,
|
||||||
|
}));
|
||||||
|
match distributions.0.entry(filename.version) {
|
||||||
|
Entry::Occupied(mut entry) => {
|
||||||
|
entry.get_mut().insert_source(dist, vec![], compatibility);
|
||||||
|
}
|
||||||
|
Entry::Vacant(entry) => {
|
||||||
|
entry.insert(PrioritizedDist::from_source(dist, vec![], compatibility));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn source_dist_compatibility(
|
||||||
|
filename: &SourceDistFilename,
|
||||||
|
no_build: &NoBuild,
|
||||||
|
) -> SourceDistCompatibility {
|
||||||
|
// Check if source distributions are allowed for this package.
|
||||||
|
let no_build = match no_build {
|
||||||
|
NoBuild::None => false,
|
||||||
|
NoBuild::All => true,
|
||||||
|
NoBuild::Packages(packages) => packages.contains(&filename.name),
|
||||||
|
};
|
||||||
|
|
||||||
|
if no_build {
|
||||||
|
return SourceDistCompatibility::Incompatible(IncompatibleSource::NoBuild);
|
||||||
|
}
|
||||||
|
|
||||||
|
SourceDistCompatibility::Compatible
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wheel_compatibility(
|
||||||
|
filename: &WheelFilename,
|
||||||
|
tags: &Tags,
|
||||||
|
no_binary: &NoBinary,
|
||||||
|
) -> WheelCompatibility {
|
||||||
|
// Check if binaries are allowed for this package.
|
||||||
|
let no_binary = match no_binary {
|
||||||
|
NoBinary::None => false,
|
||||||
|
NoBinary::All => true,
|
||||||
|
NoBinary::Packages(packages) => packages.contains(&filename.name),
|
||||||
|
};
|
||||||
|
|
||||||
|
if no_binary {
|
||||||
|
return WheelCompatibility::Incompatible(IncompatibleWheel::NoBinary);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine a compatibility for the wheel based on tags.
|
||||||
|
WheelCompatibility::from(filename.compatibility(tags))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the [`FlatDistributions`] for the given package name.
|
||||||
|
pub fn get(&self, package_name: &PackageName) -> Option<&FlatDistributions> {
|
||||||
|
self.index.get(package_name)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if there are any offline `--find-links` entries.
|
||||||
|
pub fn offline(&self) -> bool {
|
||||||
|
self.offline
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A set of [`PrioritizedDist`] from a `--find-links` entry for a single package, indexed
|
||||||
|
/// by [`Version`].
|
||||||
|
#[derive(Debug, Clone, Default)]
|
||||||
|
pub struct FlatDistributions(BTreeMap<Version, PrioritizedDist>);
|
||||||
|
|
||||||
|
impl FlatDistributions {
|
||||||
|
pub fn iter(&self) -> impl Iterator<Item = (&Version, &PrioritizedDist)> {
|
||||||
|
self.0.iter()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove(&mut self, version: &Version) -> Option<PrioritizedDist> {
|
||||||
|
self.0.remove(version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoIterator for FlatDistributions {
|
||||||
|
type Item = (Version, PrioritizedDist);
|
||||||
|
type IntoIter = std::collections::btree_map::IntoIter<Version, PrioritizedDist>;
|
||||||
|
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
self.0.into_iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<FlatDistributions> for BTreeMap<Version, PrioritizedDist> {
|
||||||
|
fn from(distributions: FlatDistributions) -> Self {
|
||||||
|
distributions.0
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
pub use dependency_mode::DependencyMode;
|
pub use dependency_mode::DependencyMode;
|
||||||
pub use error::ResolveError;
|
pub use error::ResolveError;
|
||||||
pub use exclusions::Exclusions;
|
pub use exclusions::Exclusions;
|
||||||
|
pub use flat_index::FlatIndex;
|
||||||
pub use manifest::Manifest;
|
pub use manifest::Manifest;
|
||||||
pub use options::{Options, OptionsBuilder};
|
pub use options::{Options, OptionsBuilder};
|
||||||
pub use preferences::{Preference, PreferenceError};
|
pub use preferences::{Preference, PreferenceError};
|
||||||
|
@ -24,6 +25,7 @@ mod dependency_provider;
|
||||||
mod editables;
|
mod editables;
|
||||||
mod error;
|
mod error;
|
||||||
mod exclusions;
|
mod exclusions;
|
||||||
|
mod flat_index;
|
||||||
mod manifest;
|
mod manifest;
|
||||||
mod options;
|
mod options;
|
||||||
mod pins;
|
mod pins;
|
||||||
|
|
|
@ -26,7 +26,7 @@ use pep508_rs::{MarkerEnvironment, Requirement};
|
||||||
use platform_tags::Tags;
|
use platform_tags::Tags;
|
||||||
use pypi_types::Metadata23;
|
use pypi_types::Metadata23;
|
||||||
pub(crate) use urls::Urls;
|
pub(crate) use urls::Urls;
|
||||||
use uv_client::{FlatIndex, RegistryClient};
|
use uv_client::RegistryClient;
|
||||||
use uv_configuration::{Constraints, Overrides};
|
use uv_configuration::{Constraints, Overrides};
|
||||||
use uv_distribution::DistributionDatabase;
|
use uv_distribution::DistributionDatabase;
|
||||||
use uv_interpreter::Interpreter;
|
use uv_interpreter::Interpreter;
|
||||||
|
@ -36,6 +36,7 @@ use uv_types::{BuildContext, InstalledPackagesProvider};
|
||||||
use crate::candidate_selector::{CandidateDist, CandidateSelector};
|
use crate::candidate_selector::{CandidateDist, CandidateSelector};
|
||||||
use crate::editables::Editables;
|
use crate::editables::Editables;
|
||||||
use crate::error::ResolveError;
|
use crate::error::ResolveError;
|
||||||
|
use crate::flat_index::FlatIndex;
|
||||||
use crate::manifest::Manifest;
|
use crate::manifest::Manifest;
|
||||||
use crate::pins::FilePins;
|
use crate::pins::FilePins;
|
||||||
use crate::preferences::Preferences;
|
use crate::preferences::Preferences;
|
||||||
|
|
|
@ -6,12 +6,13 @@ use chrono::{DateTime, Utc};
|
||||||
use distribution_types::{Dist, IndexLocations};
|
use distribution_types::{Dist, IndexLocations};
|
||||||
use platform_tags::Tags;
|
use platform_tags::Tags;
|
||||||
use pypi_types::Metadata23;
|
use pypi_types::Metadata23;
|
||||||
use uv_client::{FlatIndex, RegistryClient};
|
use uv_client::RegistryClient;
|
||||||
use uv_configuration::{NoBinary, NoBuild};
|
use uv_configuration::{NoBinary, NoBuild};
|
||||||
use uv_distribution::DistributionDatabase;
|
use uv_distribution::DistributionDatabase;
|
||||||
use uv_normalize::PackageName;
|
use uv_normalize::PackageName;
|
||||||
use uv_types::BuildContext;
|
use uv_types::BuildContext;
|
||||||
|
|
||||||
|
use crate::flat_index::FlatIndex;
|
||||||
use crate::python_requirement::PythonRequirement;
|
use crate::python_requirement::PythonRequirement;
|
||||||
use crate::version_map::VersionMap;
|
use crate::version_map::VersionMap;
|
||||||
use crate::yanks::AllowedYanks;
|
use crate::yanks::AllowedYanks;
|
||||||
|
|
|
@ -14,11 +14,12 @@ use pep440_rs::{Version, VersionSpecifiers};
|
||||||
use platform_tags::Tags;
|
use platform_tags::Tags;
|
||||||
use pypi_types::{HashDigest, Yanked};
|
use pypi_types::{HashDigest, Yanked};
|
||||||
use rkyv::{de::deserializers::SharedDeserializeMap, Deserialize};
|
use rkyv::{de::deserializers::SharedDeserializeMap, Deserialize};
|
||||||
use uv_client::{FlatDistributions, OwnedArchive, SimpleMetadata, VersionFiles};
|
use uv_client::{OwnedArchive, SimpleMetadata, VersionFiles};
|
||||||
use uv_configuration::{NoBinary, NoBuild};
|
use uv_configuration::{NoBinary, NoBuild};
|
||||||
use uv_normalize::PackageName;
|
use uv_normalize::PackageName;
|
||||||
use uv_warnings::warn_user_once;
|
use uv_warnings::warn_user_once;
|
||||||
|
|
||||||
|
use crate::flat_index::FlatDistributions;
|
||||||
use crate::{python_requirement::PythonRequirement, yanks::AllowedYanks};
|
use crate::{python_requirement::PythonRequirement, yanks::AllowedYanks};
|
||||||
|
|
||||||
/// A map from versions to distributions.
|
/// A map from versions to distributions.
|
||||||
|
|
|
@ -14,12 +14,12 @@ use distribution_types::{IndexLocations, Resolution, SourceDist};
|
||||||
use pep508_rs::{MarkerEnvironment, Requirement, StringVersion};
|
use pep508_rs::{MarkerEnvironment, Requirement, StringVersion};
|
||||||
use platform_tags::{Arch, Os, Platform, Tags};
|
use platform_tags::{Arch, Os, Platform, Tags};
|
||||||
use uv_cache::Cache;
|
use uv_cache::Cache;
|
||||||
use uv_client::{FlatIndex, RegistryClientBuilder};
|
use uv_client::RegistryClientBuilder;
|
||||||
use uv_configuration::{BuildKind, Constraints, NoBinary, NoBuild, Overrides, SetupPyStrategy};
|
use uv_configuration::{BuildKind, Constraints, NoBinary, NoBuild, Overrides, SetupPyStrategy};
|
||||||
use uv_interpreter::{find_default_python, Interpreter, PythonEnvironment};
|
use uv_interpreter::{find_default_python, Interpreter, PythonEnvironment};
|
||||||
use uv_resolver::{
|
use uv_resolver::{
|
||||||
DisplayResolutionGraph, Exclusions, InMemoryIndex, Manifest, Options, OptionsBuilder,
|
DisplayResolutionGraph, Exclusions, FlatIndex, InMemoryIndex, Manifest, Options,
|
||||||
PreReleaseMode, Preference, ResolutionGraph, ResolutionMode, Resolver,
|
OptionsBuilder, PreReleaseMode, Preference, ResolutionGraph, ResolutionMode, Resolver,
|
||||||
};
|
};
|
||||||
use uv_types::{BuildContext, BuildIsolation, EmptyInstalledPackages, SourceBuildTrait};
|
use uv_types::{BuildContext, BuildIsolation, EmptyInstalledPackages, SourceBuildTrait};
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,7 @@ use platform_tags::Tags;
|
||||||
use requirements_txt::EditableRequirement;
|
use requirements_txt::EditableRequirement;
|
||||||
use uv_auth::{KeyringProvider, GLOBAL_AUTH_STORE};
|
use uv_auth::{KeyringProvider, GLOBAL_AUTH_STORE};
|
||||||
use uv_cache::Cache;
|
use uv_cache::Cache;
|
||||||
use uv_client::{
|
use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder};
|
||||||
BaseClientBuilder, Connectivity, FlatIndex, FlatIndexClient, RegistryClientBuilder,
|
|
||||||
};
|
|
||||||
use uv_configuration::{
|
use uv_configuration::{
|
||||||
ConfigSettings, Constraints, IndexStrategy, NoBinary, NoBuild, Overrides, SetupPyStrategy,
|
ConfigSettings, Constraints, IndexStrategy, NoBinary, NoBuild, Overrides, SetupPyStrategy,
|
||||||
Upgrade,
|
Upgrade,
|
||||||
|
@ -36,8 +34,8 @@ use uv_requirements::{
|
||||||
RequirementsSource, RequirementsSpecification, SourceTreeResolver,
|
RequirementsSource, RequirementsSpecification, SourceTreeResolver,
|
||||||
};
|
};
|
||||||
use uv_resolver::{
|
use uv_resolver::{
|
||||||
AnnotationStyle, DependencyMode, DisplayResolutionGraph, Exclusions, InMemoryIndex, Manifest,
|
AnnotationStyle, DependencyMode, DisplayResolutionGraph, Exclusions, FlatIndex, InMemoryIndex,
|
||||||
OptionsBuilder, PreReleaseMode, PythonRequirement, ResolutionMode, Resolver,
|
Manifest, OptionsBuilder, PreReleaseMode, PythonRequirement, ResolutionMode, Resolver,
|
||||||
};
|
};
|
||||||
use uv_toolchain::PythonVersion;
|
use uv_toolchain::PythonVersion;
|
||||||
use uv_types::{BuildIsolation, EmptyInstalledPackages, InFlight};
|
use uv_types::{BuildIsolation, EmptyInstalledPackages, InFlight};
|
||||||
|
|
|
@ -21,8 +21,7 @@ use requirements_txt::EditableRequirement;
|
||||||
use uv_auth::{KeyringProvider, GLOBAL_AUTH_STORE};
|
use uv_auth::{KeyringProvider, GLOBAL_AUTH_STORE};
|
||||||
use uv_cache::Cache;
|
use uv_cache::Cache;
|
||||||
use uv_client::{
|
use uv_client::{
|
||||||
BaseClientBuilder, Connectivity, FlatIndex, FlatIndexClient, RegistryClient,
|
BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClient, RegistryClientBuilder,
|
||||||
RegistryClientBuilder,
|
|
||||||
};
|
};
|
||||||
use uv_configuration::{
|
use uv_configuration::{
|
||||||
ConfigSettings, Constraints, IndexStrategy, NoBinary, NoBuild, Overrides, Reinstall,
|
ConfigSettings, Constraints, IndexStrategy, NoBinary, NoBuild, Overrides, Reinstall,
|
||||||
|
@ -38,8 +37,8 @@ use uv_requirements::{
|
||||||
RequirementsSpecification, SourceTreeResolver,
|
RequirementsSpecification, SourceTreeResolver,
|
||||||
};
|
};
|
||||||
use uv_resolver::{
|
use uv_resolver::{
|
||||||
DependencyMode, Exclusions, InMemoryIndex, Manifest, Options, OptionsBuilder, PreReleaseMode,
|
DependencyMode, Exclusions, FlatIndex, InMemoryIndex, Manifest, Options, OptionsBuilder,
|
||||||
Preference, ResolutionGraph, ResolutionMode, Resolver,
|
PreReleaseMode, Preference, ResolutionGraph, ResolutionMode, Resolver,
|
||||||
};
|
};
|
||||||
use uv_types::{BuildIsolation, InFlight};
|
use uv_types::{BuildIsolation, InFlight};
|
||||||
use uv_warnings::warn_user;
|
use uv_warnings::warn_user;
|
||||||
|
|
|
@ -16,8 +16,7 @@ use requirements_txt::EditableRequirement;
|
||||||
use uv_auth::{KeyringProvider, GLOBAL_AUTH_STORE};
|
use uv_auth::{KeyringProvider, GLOBAL_AUTH_STORE};
|
||||||
use uv_cache::{ArchiveTarget, ArchiveTimestamp, Cache};
|
use uv_cache::{ArchiveTarget, ArchiveTimestamp, Cache};
|
||||||
use uv_client::{
|
use uv_client::{
|
||||||
BaseClientBuilder, Connectivity, FlatIndex, FlatIndexClient, RegistryClient,
|
BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClient, RegistryClientBuilder,
|
||||||
RegistryClientBuilder,
|
|
||||||
};
|
};
|
||||||
use uv_configuration::{
|
use uv_configuration::{
|
||||||
ConfigSettings, IndexStrategy, NoBinary, NoBuild, Reinstall, SetupPyStrategy,
|
ConfigSettings, IndexStrategy, NoBinary, NoBuild, Reinstall, SetupPyStrategy,
|
||||||
|
@ -30,7 +29,7 @@ use uv_requirements::{
|
||||||
ExtrasSpecification, NamedRequirementsResolver, RequirementsSource, RequirementsSpecification,
|
ExtrasSpecification, NamedRequirementsResolver, RequirementsSource, RequirementsSpecification,
|
||||||
SourceTreeResolver,
|
SourceTreeResolver,
|
||||||
};
|
};
|
||||||
use uv_resolver::{DependencyMode, InMemoryIndex, Manifest, OptionsBuilder, Resolver};
|
use uv_resolver::{DependencyMode, FlatIndex, InMemoryIndex, Manifest, OptionsBuilder, Resolver};
|
||||||
use uv_types::{BuildIsolation, EmptyInstalledPackages, InFlight};
|
use uv_types::{BuildIsolation, EmptyInstalledPackages, InFlight};
|
||||||
use uv_warnings::warn_user;
|
use uv_warnings::warn_user;
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,12 @@ use distribution_types::{DistributionMetadata, IndexLocations, Name, ResolvedDis
|
||||||
use pep508_rs::Requirement;
|
use pep508_rs::Requirement;
|
||||||
use uv_auth::{KeyringProvider, GLOBAL_AUTH_STORE};
|
use uv_auth::{KeyringProvider, GLOBAL_AUTH_STORE};
|
||||||
use uv_cache::Cache;
|
use uv_cache::Cache;
|
||||||
use uv_client::{Connectivity, FlatIndex, FlatIndexClient, RegistryClientBuilder};
|
use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder};
|
||||||
use uv_configuration::{ConfigSettings, IndexStrategy, NoBinary, NoBuild, SetupPyStrategy};
|
use uv_configuration::{ConfigSettings, IndexStrategy, NoBinary, NoBuild, SetupPyStrategy};
|
||||||
use uv_dispatch::BuildDispatch;
|
use uv_dispatch::BuildDispatch;
|
||||||
use uv_fs::Simplified;
|
use uv_fs::Simplified;
|
||||||
use uv_interpreter::{find_default_python, find_requested_python, Error};
|
use uv_interpreter::{find_default_python, find_requested_python, Error};
|
||||||
use uv_resolver::{InMemoryIndex, OptionsBuilder};
|
use uv_resolver::{FlatIndex, InMemoryIndex, OptionsBuilder};
|
||||||
use uv_types::{BuildContext, BuildIsolation, InFlight};
|
use uv_types::{BuildContext, BuildIsolation, InFlight};
|
||||||
|
|
||||||
use crate::commands::ExitStatus;
|
use crate::commands::ExitStatus;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue