Skip to content

Commit

Permalink
fix: compatible iter content working with pdm@next
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed Mar 21, 2024
1 parent 65d5584 commit a7920e4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
53 changes: 51 additions & 2 deletions pdm.lock

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

10 changes: 8 additions & 2 deletions src/pdm_download/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import defaultdict
from concurrent.futures import Future, ThreadPoolExecutor
from pathlib import Path
from typing import TYPE_CHECKING, Iterable, Sequence, cast
from typing import TYPE_CHECKING, Any, Iterable, Iterator, Sequence, cast

from pdm import termui
from pdm.cli.commands.base import BaseCommand
Expand All @@ -32,6 +32,12 @@ class FileHash(TypedDict):
file: str


def _iter_content_compat(resp: Any, chunk_size: int) -> Iterator[bytes]:
if hasattr(resp, "iter_content"):
return resp.iter_content(chunk_size)
return resp.iter_bytes(chunk_size)


def _download_package(project: Project, package: FileHash, dest: Path) -> None:
from unearth import Link

Expand All @@ -43,7 +49,7 @@ def _download_package(project: Project, package: FileHash, dest: Path) -> None:
package.get("file", Link(package["url"]).filename)
).open("wb") as fp:
resp.raise_for_status()
for chunk in resp.iter_content(chunk_size=8192):
for chunk in _iter_content_compat(resp, chunk_size=8192):
hasher.update(chunk)
fp.write(chunk)
if hasher.hexdigest() != hash_value:
Expand Down

0 comments on commit a7920e4

Please sign in to comment.