Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 440 pre-release handling - part 2 #7236

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 10 additions & 3 deletions src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,18 +520,25 @@ def find_latest_package(
from poetry.version.version_selector import VersionSelector

# find the latest version allowed in this pool
requires = root.all_requires
if package.is_direct_origin():
requires = root.all_requires

for dep in requires:
if dep.name == package.name and dep.source_type == package.source_type:
provider = Provider(root, self.poetry.pool, NullIO())
return provider.search_for_direct_origin_dependency(dep)

allow_prereleases = False
for dep in requires:
if dep.name == package.name:
allow_prereleases = dep.allows_prereleases()
break

name = package.name
selector = VersionSelector(self.poetry.pool)

return selector.find_best_candidate(name, f">={package.pretty_version}")
return selector.find_best_candidate(
name, f">={package.pretty_version}", allow_prereleases
)

def get_update_status(self, latest: Package, package: Package) -> str:
from poetry.core.constraints.version import parse_constraint
Expand Down
23 changes: 2 additions & 21 deletions src/poetry/repositories/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from packaging.utils import canonicalize_name
from poetry.core.constraints.version import Version
from poetry.core.constraints.version import VersionRange

from poetry.repositories.abstract_repository import AbstractRepository
from poetry.repositories.exceptions import PackageNotFound
Expand Down Expand Up @@ -34,11 +33,10 @@ def packages(self) -> list[Package]:

def find_packages(self, dependency: Dependency) -> list[Package]:
packages = []
constraint, allow_prereleases = self._get_constraints_from_dependency(
dependency
)
ignored_pre_release_packages = []

constraint = dependency.constraint
allow_prereleases = dependency.allows_prereleases()
for package in self._find_packages(dependency.name, constraint):
if package.yanked and not isinstance(constraint, Version):
# PEP 592: yanked files are always ignored, unless they are the only
Expand Down Expand Up @@ -92,23 +90,6 @@ def search(self, query: str) -> list[Package]:

return results

@staticmethod
def _get_constraints_from_dependency(
dependency: Dependency,
) -> tuple[VersionConstraint, bool]:
constraint = dependency.constraint

allow_prereleases = dependency.allows_prereleases()
if isinstance(constraint, VersionRange) and (
constraint.max is not None
and constraint.max.is_unstable()
or constraint.min is not None
and constraint.min.is_unstable()
):
allow_prereleases = True

return constraint, allow_prereleases

def _find_packages(
self, name: NormalizedName, constraint: VersionConstraint
) -> list[Package]:
Expand Down
21 changes: 12 additions & 9 deletions tests/puzzle/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,7 @@ def provider(root: ProjectPackage, pool: RepositoryPool) -> Provider:
(Dependency("foo", "<2"), [Package("foo", "1")]),
(Dependency("foo", "<2", extras=["bar"]), [Package("foo", "1")]),
(Dependency("foo", ">=1"), [Package("foo", "2"), Package("foo", "1")]),
(
Dependency("foo", ">=1a"),
[
Package("foo", "3a"),
Package("foo", "2"),
Package("foo", "2a"),
Package("foo", "1"),
],
),
(Dependency("foo", ">=1a"), [Package("foo", "2"), Package("foo", "1")]),
(
Dependency("foo", ">=1", allows_prereleases=True),
[
Expand All @@ -101,6 +93,17 @@ def test_search_for(
repository.add_package(foo2a)
repository.add_package(foo2)
repository.add_package(foo3a)
# TODO: remove workaround when poetry-core with
# https://github.com/python-poetry/poetry-core/pull/543 is available
if str(dependency.constraint) == ">=1a":
result = provider.search_for(dependency)
assert result == expected or result == [
Package("foo", "3a"),
Package("foo", "2"),
Package("foo", "2a"),
Package("foo", "1"),
]
return
assert provider.search_for(dependency) == expected


Expand Down