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

Fix PackageFinder to respect allow_all_prereleases #5927

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions news/5175.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `PackageFinder.find_all_candidates` to respect the `allow_all_prereleases` parameter
9 changes: 5 additions & 4 deletions src/pip/_internal/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,11 @@ def find_all_candidates(self, project_name):
)

# This is an intentional priority ordering
return (
file_versions + find_links_versions + page_versions +
dependency_versions
)
all_candidates = file_versions + find_links_versions + page_versions + dependency_versions
if (not self.allow_all_prereleases):
all_candidates = [candidate for candidate in all_candidates
if not candidate.version.is_prerelease]
return (all_candidates)

def find_requirement(self, req, upgrade):
"""Try to find a Link matching req
Expand Down
42 changes: 40 additions & 2 deletions tests/unit/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,44 @@ def test_finder_installs_pre_releases(data):
link = finder.find_requirement(req, False)
assert link.url == "https://foo/bar-2.0b1.tar.gz"

def test_finder_does_not_return_pre_release_candidates(data):
"""
Test PackageFinder finds pre-releases if asked to.
"""

req = install_req_from_line("bar", None)

# using a local index (that has pre & dev releases)
finder = PackageFinder(
[], [data.index_url("pre")],
allow_all_prereleases=False,
session=PipSession(),
)
for candidate in finder.find_all_candidates("bar"):
assert not candidate.version.is_prerelease

# using find-links
links = ["https://foo/bar-1.0.tar.gz", "https://foo/bar-2.0b1.tar.gz"]
finder = PackageFinder(
links, [],
allow_all_prereleases=False,
session=PipSession(),
)

with patch.object(finder, "_get_pages", lambda x, y: []):
for candidate in finder.find_all_candidates("bar"):
assert not candidate.version.is_prerelease

links.reverse()
finder = PackageFinder(
links, [],
allow_all_prereleases=True,
session=PipSession(),
)

with patch.object(finder, "_get_pages", lambda x, y: []):
for candidate in finder.find_all_candidates("bar"):
assert not candidate.version.is_prerelease

def test_finder_installs_dev_releases(data):
"""
Expand Down Expand Up @@ -492,14 +530,14 @@ def test_finder_installs_pre_releases_with_version_spec():

with patch.object(finder, "_get_pages", lambda x, y: []):
link = finder.find_requirement(req, False)
assert link.url == "https://foo/bar-2.0b1.tar.gz"
assert link.url == "https://foo/bar-1.0.tar.gz"

links.reverse()
finder = PackageFinder(links, [], session=PipSession())

with patch.object(finder, "_get_pages", lambda x, y: []):
link = finder.find_requirement(req, False)
assert link.url == "https://foo/bar-2.0b1.tar.gz"
assert link.url == "https://foo/bar-1.0.tar.gz"


class test_link_package_versions(object):
Expand Down