Skip to content

Commit

Permalink
🐛 Exclude 5.0rc1 when <5 is requested (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelange authored Mar 13, 2024
1 parent c892f63 commit 72d2d6d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/pipgrip/libs/mixology/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#
# SPDX-License-Identifier: BSD-3-Clause
# flake8: noqa:A002,A003
from copy import deepcopy
from typing import Any, NoReturn, Optional
from typing import Union as _Union

Expand Down Expand Up @@ -315,6 +316,21 @@ def is_strictly_lower(self, other): # type: (Range) -> bool
return not self.include_max or not other.include_min

def is_strictly_higher(self, other): # type: (Range) -> bool
if (
self.is_single_version()
and self.max is not None
and other.max is not None
and self.max.is_prerelease()
and not other.max.is_prerelease()
and not other.include_max
and self.max.equals_without_prerelease(other.max)
):
# in pip, `<5`, `<5.0`, `<5.0.0` are shorthand for `<5.0.0-alpha.0`.
# e.g. `pip install --pre django<5.0` will not install django==5.0rc1
# although technically 5.0rc1 < 5.0 according to semver.
# mimic this behaviour here (check 5.0rc1 against <5.0.0-alpha.0)
other = deepcopy(other)
other._max = other.max.first_prerelease
return other.is_strictly_lower(self)

def is_adjacent_to(self, other): # type: (Range) -> bool
Expand Down
27 changes: 27 additions & 0 deletions tests/tests_mixology/test_basic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,30 @@ def test_circular_dependency(source):
source.add("bar", "1.0.0", deps={"foo": "1.0.0"})

check_solver_result(source, {"foo": "1.0.0", "bar": "1.0.0"})


def test_prerelease_lte(source):
source.root_dep("foo", "<=5")

source.add("foo", "4.1.1")
source.add("foo", "5.0rc1")

check_solver_result(source, {"foo": "5.0rc1"})


def test_prerelease_lt(source):
source.root_dep("foo", "<5")

source.add("foo", "4.1.1")
source.add("foo", "5.0rc1")

check_solver_result(source, {"foo": "4.1.1"})


def test_prerelease_gte(source):
source.root_dep("foo", ">=5.0.0a0")

source.add("foo", "4.1.1")
source.add("foo", "5.0rc1")

check_solver_result(source, {"foo": "5.0rc1"})
15 changes: 15 additions & 0 deletions tests/tests_mixology/test_unsolvable.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ def test_no_version_matching_constraint(source):
)


def test_prerelease(source):
source.root_dep("foo", "<5")

source.add("foo", "5.0rc1")
source.add("foo", "5.0")

check_solver_result(
source,
error=(
"Because root depends on foo (<5) "
"which doesn't match any versions, version solving failed."
),
)


def test_no_version_that_matches_combined_constraints(source):
source.root_dep("foo", "1.0.0")
source.root_dep("bar", "1.0.0")
Expand Down

0 comments on commit 72d2d6d

Please sign in to comment.