Skip to content

Commit

Permalink
lazy-wheel robustness, update cachecontrol (#8941)
Browse files Browse the repository at this point in the history
- avoid endless recursion if server supports range requests, but range requests keep failing
- require cachecontrol 0.14.0 for fix concerning range requests
  • Loading branch information
radoering authored Feb 4, 2024
1 parent 981d411 commit d00ad15
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ python = "^3.8"
poetry-core = "1.9.0"
poetry-plugin-export = "^1.6.0"
build = "^1.0.3"
cachecontrol = { version = "^0.13.0", extras = ["filecache"] }
cachecontrol = { version = "^0.14.0", extras = ["filecache"] }
cleo = "^2.1.0"
crashtest = "^0.4.1"
dulwich = "^0.21.2"
Expand Down
4 changes: 3 additions & 1 deletion src/poetry/repositories/http_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def _get_info_from_wheel(self, url: str) -> PackageInfo:

# If "lazy-wheel" is enabled and the domain supports range requests
# or we don't know yet, we try range requests.
raise_accepts_ranges = self._lazy_wheel
if self._lazy_wheel and self._supports_range_requests.get(netloc, True):
try:
package_info = PackageInfo.from_metadata(
Expand All @@ -124,6 +125,7 @@ def _get_info_from_wheel(self, url: str) -> PackageInfo:
except HTTPRangeRequestUnsupported:
# Do not set to False if we already know that the domain supports
# range requests for some URLs!
raise_accepts_ranges = False
if netloc not in self._supports_range_requests:
self._supports_range_requests[netloc] = False
else:
Expand All @@ -132,7 +134,7 @@ def _get_info_from_wheel(self, url: str) -> PackageInfo:

try:
with self._cached_or_downloaded_file(
link, raise_accepts_ranges=self._lazy_wheel
link, raise_accepts_ranges=raise_accepts_ranges
) as filepath:
return PackageInfo.from_wheel(filepath)
except HTTPRangeRequestSupported:
Expand Down
6 changes: 5 additions & 1 deletion tests/repositories/test_http_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,21 @@ def test_get_info_from_wheel_state_sequence(mocker: MockerFixture) -> None:
repo._get_info_from_wheel(url)
assert mock_metadata_from_wheel_url.call_count == 1
assert mock_download.call_count == 1
assert mock_download.call_args[1]["raise_accepts_ranges"] is False

# 2. only download
repo._get_info_from_wheel(url)
assert mock_metadata_from_wheel_url.call_count == 1
assert mock_download.call_count == 2
assert mock_download.call_args[1]["raise_accepts_ranges"] is True

# 3. range request and download
# 3. download and range request
mock_metadata_from_wheel_url.side_effect = None
mock_download.side_effect = HTTPRangeRequestSupported
repo._get_info_from_wheel(url)
assert mock_metadata_from_wheel_url.call_count == 2
assert mock_download.call_count == 3
assert mock_download.call_args[1]["raise_accepts_ranges"] is True

# 4. only range request
repo._get_info_from_wheel(url)
Expand All @@ -142,6 +145,7 @@ def test_get_info_from_wheel_state_sequence(mocker: MockerFixture) -> None:
repo._get_info_from_wheel(url)
assert mock_metadata_from_wheel_url.call_count == 4
assert mock_download.call_count == 4
assert mock_download.call_args[1]["raise_accepts_ranges"] is False

# 6. only range request
mock_metadata_from_wheel_url.side_effect = None
Expand Down

0 comments on commit d00ad15

Please sign in to comment.