Skip to content

Commit

Permalink
dependency: do not implicitly allow prereleases since this is not PEP…
Browse files Browse the repository at this point in the history
… 440 compliant and counterproductive (If only a prerelease fulfills a constraint, we choose it anyway. If a stable release fulfills a constraint, we shouldn't choose a prerelease if not explicitly requested.)
  • Loading branch information
radoering committed Jan 20, 2023
1 parent debbbb3 commit 128c2cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
10 changes: 0 additions & 10 deletions src/poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from packaging.utils import canonicalize_name

from poetry.core.constraints.generic import parse_constraint as parse_generic_constraint
from poetry.core.constraints.version import VersionRangeConstraint
from poetry.core.constraints.version import parse_constraint
from poetry.core.packages.dependency_group import MAIN_GROUP
from poetry.core.packages.specification import PackageSpecification
Expand Down Expand Up @@ -71,15 +70,6 @@ def __init__(
groups = [MAIN_GROUP]

self._groups = frozenset(groups)

if (
isinstance(self._constraint, VersionRangeConstraint)
and self._constraint.min
):
allows_prereleases = (
allows_prereleases or self._constraint.min.is_unstable()
)

self._allows_prereleases = allows_prereleases

self._python_versions = "*"
Expand Down
24 changes: 13 additions & 11 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@


@pytest.mark.parametrize(
"constraint,result",
"constraint",
[
("^1.0", False),
("^1.0.dev0", True),
("^1.0.0", False),
("^1.0.0.dev0", True),
("^1.0.0.alpha0", True),
("^1.0.0.alpha0+local", True),
("^1.0.0.rc0+local", True),
("^1.0.0-1", False),
"^1.0",
"^1.0.dev0",
"^1.0.0",
"^1.0.0.dev0",
"^1.0.0.alpha0",
"^1.0.0.alpha0+local",
"^1.0.0.rc0+local",
"^1.0.0-1",
],
)
def test_allows_prerelease(constraint: str, result: bool) -> None:
assert Dependency("A", constraint).allows_prereleases() == result
@pytest.mark.parametrize("allows_prereleases", [False, True])
def test_allows_prerelease(constraint: str, allows_prereleases: bool) -> None:
dependency = Dependency("A", constraint, allows_prereleases=allows_prereleases)
assert dependency.allows_prereleases() == allows_prereleases


def test_to_pep_508() -> None:
Expand Down

0 comments on commit 128c2cf

Please sign in to comment.