From 9a8969903656e4f61e3d0514624bd9a3135e7ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Tue, 20 Dec 2022 12:18:56 +0100 Subject: [PATCH] repository: according to PEP 440 pre-releases should be considered "if the only available version that satisfies the version specifier is a pre-release" (no special handling of "*" constraint) --- src/poetry/repositories/repository.py | 4 +--- tests/repositories/test_legacy_repository.py | 9 +-------- tests/repositories/test_pypi_repository.py | 2 +- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/poetry/repositories/repository.py b/src/poetry/repositories/repository.py index 46ecaac7475..274ece2ae65 100644 --- a/src/poetry/repositories/repository.py +++ b/src/poetry/repositories/repository.py @@ -50,9 +50,7 @@ def find_packages(self, dependency: Dependency) -> list[Package]: and not allow_prereleases and not package.is_direct_origin() ): - if constraint.is_any(): - # we need this when all versions of the package are pre-releases - ignored_pre_release_packages.append(package) + ignored_pre_release_packages.append(package) continue packages.append(package) diff --git a/tests/repositories/test_legacy_repository.py b/tests/repositories/test_legacy_repository.py index bde7b563fc5..9503897a978 100644 --- a/tests/repositories/test_legacy_repository.py +++ b/tests/repositories/test_legacy_repository.py @@ -213,7 +213,7 @@ def test_find_packages_no_prereleases() -> None: @pytest.mark.parametrize( - ["constraint", "count"], [("*", 1), (">=1", 0), (">=19.0.0a0", 1)] + ["constraint", "count"], [("*", 1), (">=1", 1), ("<=18", 0), (">=19.0.0a0", 1)] ) def test_find_packages_only_prereleases(constraint: str, count: int) -> None: repo = MockRepository() @@ -228,13 +228,6 @@ def test_find_packages_only_prereleases(constraint: str, count: int) -> None: assert package.source_url == repo.url -def test_find_packages_only_prereleases_empty_when_not_any() -> None: - repo = MockRepository() - packages = repo.find_packages(Factory.create_dependency("black", ">=1")) - - assert len(packages) == 0 - - @pytest.mark.parametrize( ["constraint", "expected"], [ diff --git a/tests/repositories/test_pypi_repository.py b/tests/repositories/test_pypi_repository.py index 4d4e59e2539..5ab69c77f2b 100644 --- a/tests/repositories/test_pypi_repository.py +++ b/tests/repositories/test_pypi_repository.py @@ -87,7 +87,7 @@ def test_find_packages_does_not_select_prereleases_if_not_allowed() -> None: @pytest.mark.parametrize( - ["constraint", "count"], [("*", 1), (">=1", 0), (">=19.0.0a0", 1)] + ["constraint", "count"], [("*", 1), (">=1", 1), ("<=18", 0), (">=19.0.0a0", 1)] ) def test_find_packages_only_prereleases(constraint: str, count: int) -> None: repo = MockRepository()