Skip to content

Commit

Permalink
Make < exclusive for non-prerelease markers
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 22, 2024
1 parent 6afbb02 commit 134f875
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
13 changes: 10 additions & 3 deletions crates/uv-resolver/src/pubgrub/specifier.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use pubgrub::range::Range;

use pep440_rs::{Operator, PreRelease, Version, VersionSpecifier};
use pep440_rs::{Operator, PreRelease, PreReleaseKind, Version, VersionSpecifier};

use crate::ResolveError;

Expand Down Expand Up @@ -38,15 +38,22 @@ impl TryFrom<&VersionSpecifier> for PubGrubSpecifier {
let [rest @ .., last, _] = specifier.version().release() else {
return Err(ResolveError::InvalidTildeEquals(specifier.clone()));
};
let upper = pep440_rs::Version::new(rest.iter().chain([&(last + 1)]))
let upper = Version::new(rest.iter().chain([&(last + 1)]))
.with_epoch(specifier.version().epoch())
.with_dev(Some(0));
let version = specifier.version().clone();
Range::from_range_bounds(version..upper)
}
Operator::LessThan => {
let version = specifier.version().clone();
Range::strictly_lower_than(version)
if version.any_prerelease() {
Range::strictly_lower_than(version)
} else {
// Per PEP 440: "The exclusive ordered comparison <V MUST NOT allow a
// pre-release of the specified version unless the specified version is itself a
// pre-release.
Range::strictly_lower_than(version.with_pre(Some(PreRelease { kind: PreReleaseKind::Alpha, number: 0 })))
}
}
Operator::LessThanEqual => {
let version = specifier.version().clone();
Expand Down
25 changes: 18 additions & 7 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2075,12 +2075,17 @@ fn compile_yanked_version_indirect() -> Result<()> {
╰─▶ Because only the following versions of attrs are available:
attrs<=20.3.0
attrs==21.1.0
attrs>=21.2.0
attrs>=21.2.0a0
and attrs==21.1.0 is unusable because it was yanked (reason:
Installable but not importable on Python 3.4), we can conclude that
attrs>20.3.0,<21.2.0 cannot be used.
And because you require attrs>20.3.0,<21.2.0, we can conclude that the
attrs>20.3.0,<21.2.0a0 cannot be used.
And because you require attrs>20.3.0,<21.2.0a0, we can conclude that the
requirements are unsatisfiable.
hint: attrs was requested with a pre-release marker (e.g., any of:
attrs>20.3.0,<21.1.0
attrs>21.1.0,<21.2.0a0
), but pre-releases weren't enabled (try: `--prerelease=allow`)
"###
);

Expand Down Expand Up @@ -3857,8 +3862,11 @@ fn compile_constraints_incompatible_url() -> Result<()> {
----- stderr -----
× No solution found when resolving dependencies:
╰─▶ Because only anyio>=4 is available and you require anyio<4, we can
╰─▶ Because only anyio>=4a0 is available and you require anyio<4a0, we can
conclude that the requirements are unsatisfiable.
hint: anyio was requested with a pre-release marker (e.g., anyio<4a0),
but pre-releases weren't enabled (try: `--prerelease=allow`)
"###
);

Expand All @@ -3881,8 +3889,11 @@ fn index_url_in_requirements() -> Result<()> {
----- stderr -----
× No solution found when resolving dependencies:
╰─▶ Because anyio<4 was not found in the package registry and you require
anyio<4, we can conclude that the requirements are unsatisfiable.
╰─▶ Because anyio<4a0 was not found in the package registry and you require
anyio<4a0, we can conclude that the requirements are unsatisfiable.
hint: anyio was requested with a pre-release marker (e.g., anyio<4a0),
but pre-releases weren't enabled (try: `--prerelease=allow`)
"###
);

Expand Down Expand Up @@ -4285,7 +4296,7 @@ fn override_with_incompatible_constraint() -> Result<()> {
----- stderr -----
× No solution found when resolving dependencies:
╰─▶ Because you require anyio>=3.0.0 and you require anyio<3.0.0, we can
╰─▶ Because you require anyio>=3.0.0 and you require anyio<3.0.0a0, we can
conclude that the requirements are unsatisfiable.
"###
);
Expand Down

0 comments on commit 134f875

Please sign in to comment.