Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 36 additions & 40 deletions crates/uv-pep440/src/version_specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,53 +553,49 @@ impl VersionSpecifier {
// pypa/packaging disagrees: https://github.com/pypa/packaging/issues/617
other.as_ref() >= this
}
Operator::GreaterThan => Self::greater_than(this, &other),
Operator::GreaterThanEqual => other.as_ref() >= this,
Operator::LessThan => Self::less_than(this, &other),
Operator::LessThanEqual => other.as_ref() <= this,
}
}

fn less_than(this: &Version, other: &Version) -> bool {
if other.epoch() < this.epoch() {
return true;
}

// The exclusive ordered comparison <V MUST NOT allow a pre-release of the specified
// version unless the specified version is itself a pre-release. E.g., <3.1 should
// not match 3.1.dev0, but should match both 3.0.dev0 and 3.0, while <3.1.dev1 does match
// 3.1.dev0, 3.0.dev0 and 3.0.
if version::compare_release(&this.release(), &other.release()) == Ordering::Equal
&& !this.any_prerelease()
&& other.any_prerelease()
{
return false;
}
Operator::GreaterThan => {
if other.epoch() > this.epoch() {
return true;
}

other < this
}
if version::compare_release(&this.release(), &other.release()) == Ordering::Equal {
// This special case is here so that, unless the specifier itself
// includes is a post-release version, that we do not accept
// post-release versions for the version mentioned in the specifier
// (e.g. >3.1 should not match 3.0.post0, but should match 3.2.post0).
if !this.is_post() && other.is_post() {
return false;
}

fn greater_than(this: &Version, other: &Version) -> bool {
if other.epoch() > this.epoch() {
return true;
}
// We already checked that self doesn't have a local version
if other.is_local() {
return false;
}
}

if version::compare_release(&this.release(), &other.release()) == Ordering::Equal {
// This special case is here so that, unless the specifier itself
// includes is a post-release version, that we do not accept
// post-release versions for the version mentioned in the specifier
// (e.g. >3.1 should not match 3.0.post0, but should match 3.2.post0).
if !this.is_post() && other.is_post() {
return false;
other.as_ref() > this
}
Operator::GreaterThanEqual => other.as_ref() >= this,
Operator::LessThan => {
if other.epoch() < this.epoch() {
return true;
}

// We already checked that self doesn't have a local version
if other.is_local() {
return false;
// The exclusive ordered comparison <V MUST NOT allow a pre-release of the specified
// version unless the specified version is itself a pre-release. E.g., <3.1 should
// not match 3.1.dev0, but should match both 3.0.dev0 and 3.0, while <3.1.dev1 does
// match 3.1.dev0, 3.0.dev0 and 3.0.
if version::compare_release(&this.release(), &other.release()) == Ordering::Equal
&& !this.any_prerelease()
&& other.any_prerelease()
{
return false;
}

other.as_ref() < this
}
Operator::LessThanEqual => other.as_ref() <= this,
}

other > this
}

/// Whether this version specifier rejects versions below a lower cutoff.
Expand Down
Loading