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 requests auto decode file #8701

Merged
102 changes: 101 additions & 1 deletion poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ xattr = { version = "^0.10.0", markers = "sys_platform == 'darwin'" }

[tool.poetry.group.dev.dependencies]
pre-commit = ">=2.10"
pytest-httpserver = "^1.0.8"
codeskyblue marked this conversation as resolved.
Show resolved Hide resolved

[tool.poetry.group.test.dependencies]
deepdiff = "^6.3"
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def total_size(self) -> int:
def download_with_progress(self, chunk_size: int = 1024) -> Iterator[int]:
fetched_size = 0
with atomic_open(self._dest) as f:
for chunk in self._response.iter_content(chunk_size=chunk_size):
for chunk in self._response.raw.stream(chunk_size, decode_content=False):
if chunk:
f.write(chunk)
fetched_size += len(chunk)
Expand Down
18 changes: 17 additions & 1 deletion tests/utils/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import annotations
import pathlib

from typing import TYPE_CHECKING

import pytest
from pytest_httpserver import HTTPServer

from poetry.core.utils.helpers import parse_requires

from poetry.utils.helpers import get_file_hash
from poetry.utils.helpers import get_file_hash, download_file


if TYPE_CHECKING:
Expand Down Expand Up @@ -119,3 +121,17 @@ def test_guaranteed_hash(
) -> None:
file_path = fixture_dir("distributions") / "demo-0.1.0.tar.gz"
assert get_file_hash(file_path, hash_name) == expected


def test_download_file(httpserver: HTTPServer, fixture_dir: FixtureDirGetter, tmp_path: pathlib.Path) -> None:
file_path = fixture_dir("distributions") / "demo-0.1.0.tar.gz"
httpserver.expect_request("/demo-0.1.0.tar.gz").respond_with_data(
open(file_path, "rb").read(),
headers={'Content-Encoding': 'gzip'}
)
dest = tmp_path / "demo-0.1.0.tar.gz"
download_file(httpserver.url_for("/demo-0.1.0.tar.gz"), dest)
expect_sha_256 = "9fa123ad707a5c6c944743bf3e11a0e80d86cb518d3cf25320866ca3ef43e2ad"
assert get_file_hash(dest) == expect_sha_256