-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Omit wheels from lockfile based on --exclude-newer
#12299
Open
charliermarsh
wants to merge
1
commit into
main
Choose a base branch
from
charlie/exc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+205
−37
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -371,6 +371,10 @@ impl PrioritizedDist { | |
self.0.markers.or(implied_markers(&dist.filename)); | ||
} | ||
} | ||
// Track the hashes. | ||
if !compatibility.is_excluded() { | ||
self.0.hashes.extend(hashes); | ||
} | ||
// Track the highest-priority wheel. | ||
if let Some((.., existing_compatibility)) = self.best_wheel() { | ||
if compatibility.is_more_compatible(existing_compatibility) { | ||
|
@@ -379,7 +383,6 @@ impl PrioritizedDist { | |
} else { | ||
self.0.best_wheel_index = Some(self.0.wheels.len()); | ||
} | ||
self.0.hashes.extend(hashes); | ||
self.0.wheels.push((dist, compatibility)); | ||
} | ||
|
||
|
@@ -394,6 +397,10 @@ impl PrioritizedDist { | |
if compatibility.is_compatible() { | ||
self.0.markers = MarkerTree::TRUE; | ||
} | ||
// Track the hashes. | ||
if !compatibility.is_excluded() { | ||
self.0.hashes.extend(hashes); | ||
} | ||
// Track the highest-priority source. | ||
if let Some((.., existing_compatibility)) = &self.0.source { | ||
if compatibility.is_more_compatible(existing_compatibility) { | ||
|
@@ -402,7 +409,6 @@ impl PrioritizedDist { | |
} else { | ||
self.0.source = Some((dist, compatibility)); | ||
} | ||
self.0.hashes.extend(hashes); | ||
} | ||
|
||
/// Return the highest-priority distribution for the package version, if any. | ||
|
@@ -441,16 +447,19 @@ impl PrioritizedDist { | |
// wheel. We assume that all distributions have the same metadata for a given package | ||
// version. If a compatible source distribution exists, we assume we can build it, but | ||
// using the wheel is faster. | ||
// | ||
// (If the incompatible wheel should actually be ignored entirely, fall through to | ||
// using the source distribution.) | ||
( | ||
Some((wheel, WheelCompatibility::Incompatible(_))), | ||
Some((wheel, compatibility @ WheelCompatibility::Incompatible(_))), | ||
Some((sdist, SourceDistCompatibility::Compatible(_))), | ||
) => Some(CompatibleDist::IncompatibleWheel { | ||
) if !compatibility.is_excluded() => Some(CompatibleDist::IncompatibleWheel { | ||
sdist, | ||
wheel, | ||
prioritized: self, | ||
}), | ||
// Otherwise, if we have a source distribution, return it. | ||
(None, Some((sdist, SourceDistCompatibility::Compatible(_)))) => { | ||
(.., Some((sdist, SourceDistCompatibility::Compatible(_)))) => { | ||
Some(CompatibleDist::SourceDist { | ||
sdist, | ||
prioritized: self, | ||
|
@@ -497,24 +506,38 @@ impl PrioritizedDist { | |
/// a built distribution with the best wheel in this prioritized dist. | ||
pub fn built_dist(&self) -> Option<RegistryBuiltDist> { | ||
let best_wheel_index = self.0.best_wheel_index?; | ||
let wheels = self | ||
.0 | ||
.wheels | ||
.iter() | ||
.map(|(wheel, _)| wheel.clone()) | ||
.collect(); | ||
|
||
// Remove any excluded wheels from the list of wheels, and adjust the wheel index to be | ||
// relative to the filtered list. | ||
let mut adjusted_wheels = Vec::with_capacity(self.0.wheels.len()); | ||
let mut adjusted_best_index = 0; | ||
for (i, (wheel, compatibility)) in self.0.wheels.iter().enumerate() { | ||
if compatibility.is_excluded() { | ||
continue; | ||
} | ||
if i == best_wheel_index { | ||
adjusted_best_index = adjusted_wheels.len(); | ||
} | ||
adjusted_wheels.push(wheel.clone()); | ||
} | ||
|
||
let sdist = self.0.source.as_ref().map(|(sdist, _)| sdist.clone()); | ||
Some(RegistryBuiltDist { | ||
wheels, | ||
best_wheel_index, | ||
wheels: adjusted_wheels, | ||
best_wheel_index: adjusted_best_index, | ||
sdist, | ||
}) | ||
} | ||
|
||
/// If this prioritized dist has an sdist, then this creates a source | ||
/// distribution. | ||
pub fn source_dist(&self) -> Option<RegistrySourceDist> { | ||
let mut sdist = self.0.source.as_ref().map(|(sdist, _)| sdist.clone())?; | ||
let mut sdist = self | ||
.0 | ||
.source | ||
.as_ref() | ||
.filter(|(_, compatibility)| !compatibility.is_excluded()) | ||
.map(|(sdist, _)| sdist.clone())?; | ||
assert!( | ||
sdist.wheels.is_empty(), | ||
"source distribution should not have any wheels yet" | ||
|
@@ -623,6 +646,11 @@ impl WheelCompatibility { | |
matches!(self, Self::Compatible(_, _, _)) | ||
} | ||
|
||
/// Return `true` if the distribution is excluded. | ||
pub fn is_excluded(&self) -> bool { | ||
matches!(self, Self::Incompatible(IncompatibleWheel::ExcludeNewer(_))) | ||
} | ||
Comment on lines
+650
to
+652
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to not consider all |
||
|
||
/// Return `true` if the current compatibility is more compatible than another. | ||
/// | ||
/// Compatible wheels are always higher more compatible than incompatible wheels. | ||
|
@@ -650,6 +678,14 @@ impl SourceDistCompatibility { | |
matches!(self, Self::Compatible(_)) | ||
} | ||
|
||
/// Return `true` if the distribution is excluded. | ||
pub fn is_excluded(&self) -> bool { | ||
matches!( | ||
self, | ||
Self::Incompatible(IncompatibleSource::ExcludeNewer(_)) | ||
) | ||
} | ||
|
||
/// Return the higher priority compatibility. | ||
/// | ||
/// Compatible source distributions are always higher priority than incompatible source distributions. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depends on https://pypi.org/project/methodtools/0.4.7/#files, which added a wheel on August 23, 2024. So we can bump this to avoid building it from source.