Skip to content

Commit

Permalink
Clear pip's candidates cache in allow_all_wheels
Browse files Browse the repository at this point in the history
Fixes #1532

This issue only shows up for PyPI servers where we can't get hashes from
a JSON API. When pip-compile runs, `find_all_candidates` first gets
called outside of an `allow_all_wheels()` context, and pip caches the
list of candidates. Later, while pip-compile computes hashes from the
files, the effects of `allow_all_wheels()` are not seen because the
cached candidates are returned.

In order for the test to pass I've added a blank sdist for
small-fake-multi-arch so that there's always at least one candidate
when pypi_repository.get_hashes is called outside of allow_all_wheels
  • Loading branch information
Frazer McLean authored and RazerM committed Apr 4, 2022
1 parent 8540782 commit 1ccdea5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ def _wheel_support_index_min(self: Wheel, tags: List[Tag]) -> int:
Wheel.support_index_min = _wheel_support_index_min
self._available_candidates_cache = {}

# If we don't clear this cache then it can contain results from an
# earlier call when allow_all_wheels wasn't active. See GH-1532
self.finder.find_all_candidates.cache_clear()

try:
yield
finally:
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions tests/test_repository_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ def test_generate_hashes_all_platforms(capsys, pip_conf, from_line, pypi_reposit
"sha256:8d4d131cd05338e09f461ad784297efea3652e542c5fabe04a62358429a6175e",
"sha256:ad05e1371eb99f257ca00f791b755deb22e752393eb8e75bc01d651715b02ea9",
"sha256:24afa5b317b302f356fd3fc3b1cfb0aad114d509cf635ea9566052424191b944",
"sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
}

ireq = from_line("small-fake-multi-arch==0.1")

# pip caches the candidates for the current system, which means
# allow_all_wheels won't have the desired effect unless the cache is
# cleared. See GH-1532
assert pypi_repository.get_hashes(ireq) < expected

with pypi_repository.allow_all_wheels():
assert pypi_repository.get_hashes(ireq) == expected
captured = capsys.readouterr()
Expand Down

0 comments on commit 1ccdea5

Please sign in to comment.