Skip to content

Commit

Permalink
Merge branch 'main' into zb/no-wheel-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Feb 15, 2024
2 parents c79f646 + bf2ee6b commit 30bbf9c
Show file tree
Hide file tree
Showing 13 changed files with 460 additions and 109 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ derivative = { version = "2.2.0" }
directories = { version = "5.0.1" }
dirs = { version = "5.0.1" }
dunce = { version = "1.0.4" }
either = { version = "1.9.0" }
flate2 = { version = "1.0.28", default-features = false }
fs-err = { version = "2.11.0" }
fs2 = { version = "0.4.3" }
Expand All @@ -64,7 +65,7 @@ owo-colors = { version = "4.0.0" }
petgraph = { version = "0.6.4" }
platform-info = { version = "2.0.2" }
plist = { version = "1.6.0" }
pubgrub = { git = "https://github.com/zanieb/pubgrub", rev = "1b150cdbd1e6f93b1f465de9d08f499660d7f708" }
pubgrub = { git = "https://github.com/zanieb/pubgrub", rev = "9b6d89cb8a0c7902815c8b2ae99106ba322ffb14" }
pyo3 = { version = "0.20.2" }
pyo3-log = { version = "0.9.0"}
pyproject-toml = { version = "0.8.1" }
Expand Down
8 changes: 4 additions & 4 deletions crates/distribution-types/src/prioritized_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct DistMetadata {
}

impl PrioritizedDist {
/// Create a new [`PrioritizedDistribution`] from the given wheel distribution.
/// Create a new [`PrioritizedDist`] from the given wheel distribution.
pub fn from_built(
dist: Dist,
requires_python: Option<VersionSpecifiers>,
Expand Down Expand Up @@ -105,7 +105,7 @@ impl PrioritizedDist {
}
}

/// Create a new [`PrioritizedDistribution`] from the given source distribution.
/// Create a new [`PrioritizedDist`] from the given source distribution.
pub fn from_source(
dist: Dist,
requires_python: Option<VersionSpecifiers>,
Expand All @@ -125,7 +125,7 @@ impl PrioritizedDist {
}))
}

/// Insert the given built distribution into the [`PrioritizedDistribution`].
/// Insert the given built distribution into the [`PrioritizedDist`].
pub fn insert_built(
&mut self,
dist: Dist,
Expand Down Expand Up @@ -190,7 +190,7 @@ impl PrioritizedDist {
}
}

/// Insert the given source distribution into the [`PrioritizedDistribution`].
/// Insert the given source distribution into the [`PrioritizedDist`].
pub fn insert_source(
&mut self,
dist: Dist,
Expand Down
6 changes: 4 additions & 2 deletions crates/platform-tags/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::str::FromStr;
use std::sync::Arc;
use std::{cmp, num::NonZeroU32};

use rustc_hash::FxHashMap;
Expand Down Expand Up @@ -61,7 +62,8 @@ impl TagCompatibility {
#[derive(Debug, Clone)]
pub struct Tags {
/// python_tag |--> abi_tag |--> platform_tag |--> priority
map: FxHashMap<String, FxHashMap<String, FxHashMap<String, TagPriority>>>,
#[allow(clippy::type_complexity)]
map: Arc<FxHashMap<String, FxHashMap<String, FxHashMap<String, TagPriority>>>>,
}

impl Tags {
Expand All @@ -79,7 +81,7 @@ impl Tags {
.entry(platform.to_string())
.or_insert(TagPriority::try_from(index).expect("valid tag priority"));
}
Self { map }
Self { map: Arc::new(map) }
}

/// Returns the compatible tags for the given Python implementation (e.g., `cpython`), version,
Expand Down
4 changes: 2 additions & 2 deletions crates/puffin-client/src/flat_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<'a> FlatIndexClient<'a> {
}
}

/// A set of [`PrioritizedDistribution`] from a `--find-links` entry, indexed by [`PackageName`]
/// A set of [`PrioritizedDist`] from a `--find-links` entry, indexed by [`PackageName`]
/// and [`Version`].
#[derive(Debug, Clone, Default)]
pub struct FlatIndex {
Expand Down Expand Up @@ -353,7 +353,7 @@ impl FlatIndex {
}
}

/// A set of [`PrioritizedDistribution`] from a `--find-links` entry for a single package, indexed
/// 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>);
Expand Down
10 changes: 10 additions & 0 deletions crates/puffin-client/src/registry_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,16 @@ impl IntoIterator for SimpleMetadata {
}
}

impl ArchivedSimpleMetadata {
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &rkyv::Archived<SimpleMetadatum>> {
self.0.iter()
}

pub fn datum(&self, i: usize) -> Option<&rkyv::Archived<SimpleMetadatum>> {
self.0.get(i)
}
}

#[derive(Debug)]
enum MediaType {
Json,
Expand Down
12 changes: 1 addition & 11 deletions crates/puffin-git/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,6 @@ where
);
}
}
msg.push_str("\n\n");
msg.push_str("if the git CLI succeeds then `net.git-fetch-with-cli` may help here\n");
msg.push_str("https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli");
err = err.context(msg);

// Otherwise if we didn't even get to the authentication phase them we may
Expand All @@ -814,14 +811,7 @@ where
| ErrorClass::FetchHead
| ErrorClass::Ssh
| ErrorClass::Http => {
let mut msg = "network failure seems to have happened\n".to_string();
msg.push_str(
"if a proxy or similar is necessary `net.git-fetch-with-cli` may help here\n",
);
msg.push_str(
"https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli",
);
err = err.context(msg);
err = err.context("failed to connect to the repository");
}
ErrorClass::Callback => {
// This unwraps the git2 error. We're using the callback error
Expand Down
2 changes: 2 additions & 0 deletions crates/puffin-resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ chrono = { workspace = true }
clap = { workspace = true, features = ["derive"], optional = true }
dashmap = { workspace = true }
derivative = { workspace = true }
either = { workspace = true }
fs-err = { workspace = true, features = ["tokio"] }
futures = { workspace = true }
indexmap = { workspace = true }
Expand All @@ -47,6 +48,7 @@ owo-colors = { workspace = true }
petgraph = { workspace = true }
pubgrub = { workspace = true }
reqwest = { workspace = true }
rkyv = { workspace = true, features = ["strict", "validation"] }
rustc-hash = { workspace = true }
serde_json = { workspace = true }
sha2 = { workspace = true }
Expand Down
76 changes: 62 additions & 14 deletions crates/puffin-resolver/src/candidate_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use puffin_normalize::PackageName;
use crate::prerelease_mode::PreReleaseStrategy;

use crate::resolution_mode::ResolutionStrategy;
use crate::version_map::VersionMap;
use crate::version_map::{VersionMap, VersionMapDistHandle};
use crate::{Manifest, Options};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -96,7 +96,7 @@ impl CandidateSelector {
pub(crate) fn select<'a>(
&'a self,
package_name: &'a PackageName,
range: &Range<Version>,
range: &'a Range<Version>,
version_map: &'a VersionMap,
) -> Option<Candidate<'a>> {
// If the package has a preference (e.g., an existing version from an existing lockfile),
Expand Down Expand Up @@ -130,6 +130,12 @@ impl CandidateSelector {
}
};

tracing::trace!(
"selecting candidate for package {:?} with range {:?} with {} versions",
package_name,
range,
version_map.len()
);
match &self.resolution_strategy {
ResolutionStrategy::Highest => Self::select_candidate(
version_map.iter().rev(),
Expand Down Expand Up @@ -163,7 +169,7 @@ impl CandidateSelector {
/// Select the first-matching [`Candidate`] from a set of candidate versions and files,
/// preferring wheels over source distributions.
fn select_candidate<'a>(
versions: impl Iterator<Item = (&'a Version, &'a PrioritizedDist)>,
versions: impl Iterator<Item = (&'a Version, VersionMapDistHandle<'a>)>,
package_name: &'a PackageName,
range: &Range<Version>,
allow_prerelease: AllowPreRelease,
Expand All @@ -175,31 +181,46 @@ impl CandidateSelector {
}

let mut prerelease = None;
for (version, file) in versions {
if file.exclude_newer() && file.incompatible_wheel().is_none() && file.get().is_none() {
// Skip empty candidates due to exclude newer
continue;
}
let mut steps = 0;
for (version, maybe_dist) in versions {
steps += 1;

if version.any_prerelease() {
let dist = if version.any_prerelease() {
if range.contains(version) {
match allow_prerelease {
AllowPreRelease::Yes => {
let Some(dist) = maybe_dist.prioritized_dist() else {
continue;
};
tracing::trace!(
"found candidate for package {:?} with range {:?} \
after {} steps: {:?} version",
package_name,
range,
steps,
version,
);
// If pre-releases are allowed, treat them equivalently
// to stable distributions.
return Some(Candidate::new(package_name, version, file));
dist
}
AllowPreRelease::IfNecessary => {
let Some(dist) = maybe_dist.prioritized_dist() else {
continue;
};
// If pre-releases are allowed as a fallback, store the
// first-matching prerelease.
if prerelease.is_none() {
prerelease = Some(PreReleaseCandidate::IfNecessary(version, file));
prerelease = Some(PreReleaseCandidate::IfNecessary(version, dist));
}
continue;
}
AllowPreRelease::No => {
continue;
}
}
} else {
continue;
}
} else {
// If we have at least one stable release, we shouldn't allow the "if-necessary"
Expand All @@ -209,15 +230,42 @@ impl CandidateSelector {

// Always return the first-matching stable distribution.
if range.contains(version) {
return Some(Candidate::new(package_name, version, file));
let Some(dist) = maybe_dist.prioritized_dist() else {
continue;
};
tracing::trace!(
"found candidate for package {:?} with range {:?} \
after {} steps: {:?} version",
package_name,
range,
steps,
version,
);
dist
} else {
continue;
}
};

// Skip empty candidates due to exclude newer
if dist.exclude_newer() && dist.incompatible_wheel().is_none() && dist.get().is_none() {
continue;
}

return Some(Candidate::new(package_name, version, dist));
}
tracing::trace!(
"exhausted all candidates for package {:?} with range {:?} \
after {} steps",
package_name,
range,
steps,
);
match prerelease {
None => None,
Some(PreReleaseCandidate::NotNecessary) => None,
Some(PreReleaseCandidate::IfNecessary(version, file)) => {
Some(Candidate::new(package_name, version, file))
Some(PreReleaseCandidate::IfNecessary(version, dist)) => {
Some(Candidate::new(package_name, version, dist))
}
}
}
Expand Down
Loading

0 comments on commit 30bbf9c

Please sign in to comment.