From a7920e4ed93955c5231e5d73150bd6c495153bcc Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 21 Mar 2024 13:11:09 +0800 Subject: [PATCH] fix: compatible iter content working with pdm@next Signed-off-by: Frost Ming --- pdm.lock | 53 +++++++++++++++++++++++++++++++++++-- src/pdm_download/command.py | 10 +++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/pdm.lock b/pdm.lock index f28e381..b49281c 100644 --- a/pdm.lock +++ b/pdm.lock @@ -3,8 +3,8 @@ [metadata] groups = ["default", "dev"] -strategy = ["cross_platform"] -lock_version = "4.4" +strategy = ["cross_platform", "inherit_metadata"] +lock_version = "4.4.1" content_hash = "sha256:c959cb9f386bb079e868536e8c2224cd824f36be273efac99ffd13defde70731" [[package]] @@ -12,6 +12,7 @@ name = "blinker" version = "1.7.0" requires_python = ">=3.8" summary = "Fast, simple object-to-object and broadcast signaling" +groups = ["dev"] files = [ {file = "blinker-1.7.0-py3-none-any.whl", hash = "sha256:c3f865d4d54db7abc53758a01601cf343fe55b84c1de4e3fa910e420b438d5b9"}, {file = "blinker-1.7.0.tar.gz", hash = "sha256:e6820ff6fa4e4d1d8e2747c2283749c3f547e4fee112b98555cdcdae32996182"}, @@ -22,6 +23,7 @@ name = "cachecontrol" version = "0.13.1" requires_python = ">=3.7" summary = "httplib2 caching for requests" +groups = ["dev"] dependencies = [ "msgpack>=0.5.2", "requests>=2.16.0", @@ -37,6 +39,7 @@ version = "0.13.1" extras = ["filecache"] requires_python = ">=3.7" summary = "httplib2 caching for requests" +groups = ["dev"] dependencies = [ "cachecontrol==0.13.1", "filelock>=3.8.0", @@ -51,6 +54,7 @@ name = "certifi" version = "2023.11.17" requires_python = ">=3.6" summary = "Python package for providing Mozilla's CA Bundle." +groups = ["dev"] files = [ {file = "certifi-2023.11.17-py3-none-any.whl", hash = "sha256:e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474"}, {file = "certifi-2023.11.17.tar.gz", hash = "sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1"}, @@ -61,6 +65,7 @@ name = "charset-normalizer" version = "3.3.2" requires_python = ">=3.7.0" summary = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." +groups = ["dev"] files = [ {file = "charset-normalizer-3.3.2.tar.gz", hash = "sha256:f30c3cb33b24454a82faecaf01b19c18562b1e89558fb6c56de4d9118a032fd5"}, {file = "charset_normalizer-3.3.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:25baf083bf6f6b341f4121c2f3c548875ee6f5339300e08be3f2b2ba1721cdd3"}, @@ -146,6 +151,8 @@ name = "colorama" version = "0.4.6" requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" summary = "Cross-platform colored terminal text." +groups = ["dev"] +marker = "sys_platform == \"win32\"" files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, @@ -155,6 +162,7 @@ files = [ name = "distlib" version = "0.3.8" summary = "Distribution utilities" +groups = ["dev"] files = [ {file = "distlib-0.3.8-py2.py3-none-any.whl", hash = "sha256:034db59a0b96f8ca18035f36290806a9a6e6bd9d1ff91e45a7f172eb17e51784"}, {file = "distlib-0.3.8.tar.gz", hash = "sha256:1530ea13e350031b6312d8580ddb6b27a104275a31106523b8f123787f494f64"}, @@ -165,6 +173,8 @@ name = "exceptiongroup" version = "1.2.0" requires_python = ">=3.7" summary = "Backport of PEP 654 (exception groups)" +groups = ["dev"] +marker = "python_version < \"3.11\"" files = [ {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"}, {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"}, @@ -175,6 +185,7 @@ name = "filelock" version = "3.13.1" requires_python = ">=3.8" summary = "A platform independent file lock." +groups = ["dev"] files = [ {file = "filelock-3.13.1-py3-none-any.whl", hash = "sha256:57dbda9b35157b05fb3e58ee91448612eb674172fab98ee235ccb0b5bee19a1c"}, {file = "filelock-3.13.1.tar.gz", hash = "sha256:521f5f56c50f8426f5e03ad3b281b490a87ef15bc6c526f168290f0c7148d44e"}, @@ -185,6 +196,7 @@ name = "findpython" version = "0.4.1" requires_python = ">=3.7" summary = "A utility to find python versions on your system" +groups = ["dev"] dependencies = [ "packaging>=20", ] @@ -198,6 +210,7 @@ name = "idna" version = "3.6" requires_python = ">=3.5" summary = "Internationalized Domain Names in Applications (IDNA)" +groups = ["dev"] files = [ {file = "idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f"}, {file = "idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"}, @@ -208,6 +221,8 @@ name = "importlib-metadata" version = "7.0.0" requires_python = ">=3.8" summary = "Read metadata from Python packages" +groups = ["dev"] +marker = "python_version < \"3.10\"" dependencies = [ "zipp>=0.5", ] @@ -221,6 +236,8 @@ name = "importlib-resources" version = "6.1.1" requires_python = ">=3.8" summary = "Read resources from Python packages" +groups = ["dev"] +marker = "python_version < \"3.9\"" dependencies = [ "zipp>=3.1.0; python_version < \"3.10\"", ] @@ -234,6 +251,7 @@ name = "iniconfig" version = "2.0.0" requires_python = ">=3.7" summary = "brain-dead simple config-ini parsing" +groups = ["dev"] files = [ {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, @@ -244,6 +262,7 @@ name = "installer" version = "0.7.0" requires_python = ">=3.7" summary = "A library for installing Python wheels." +groups = ["dev"] files = [ {file = "installer-0.7.0-py3-none-any.whl", hash = "sha256:05d1933f0a5ba7d8d6296bb6d5018e7c94fa473ceb10cf198a92ccea19c27b53"}, {file = "installer-0.7.0.tar.gz", hash = "sha256:a26d3e3116289bb08216e0d0f7d925fcef0b0194eedfa0c944bcaaa106c4b631"}, @@ -254,6 +273,7 @@ name = "markdown-it-py" version = "3.0.0" requires_python = ">=3.8" summary = "Python port of markdown-it. Markdown parsing, done right!" +groups = ["default", "dev"] dependencies = [ "mdurl~=0.1", ] @@ -267,6 +287,7 @@ name = "mdurl" version = "0.1.2" requires_python = ">=3.7" summary = "Markdown URL utilities" +groups = ["default", "dev"] files = [ {file = "mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8"}, {file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"}, @@ -277,6 +298,7 @@ name = "msgpack" version = "1.0.7" requires_python = ">=3.8" summary = "MessagePack serializer" +groups = ["dev"] files = [ {file = "msgpack-1.0.7-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:04ad6069c86e531682f9e1e71b71c1c3937d6014a7c3e9edd2aa81ad58842862"}, {file = "msgpack-1.0.7-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:cca1b62fe70d761a282496b96a5e51c44c213e410a964bdffe0928e611368329"}, @@ -341,6 +363,7 @@ name = "packaging" version = "23.2" requires_python = ">=3.7" summary = "Core utilities for Python packages" +groups = ["dev"] files = [ {file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, @@ -351,6 +374,7 @@ name = "pdm" version = "2.10.4" requires_python = ">=3.7" summary = "A modern Python package and dependency manager supporting the latest PEP standards" +groups = ["dev"] dependencies = [ "blinker", "cachecontrol[filecache]>=0.13.0", @@ -384,6 +408,7 @@ version = "2.10.4" extras = ["pytest"] requires_python = ">=3.7" summary = "A modern Python package and dependency manager supporting the latest PEP standards" +groups = ["dev"] dependencies = [ "pdm==2.10.4", "pytest", @@ -399,6 +424,7 @@ name = "platformdirs" version = "4.1.0" requires_python = ">=3.8" summary = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +groups = ["dev"] files = [ {file = "platformdirs-4.1.0-py3-none-any.whl", hash = "sha256:11c8f37bcca40db96d8144522d925583bdb7a31f7b0e37e3ed4318400a8e2380"}, {file = "platformdirs-4.1.0.tar.gz", hash = "sha256:906d548203468492d432bcb294d4bc2fff751bf84971fbb2c10918cc206ee420"}, @@ -409,6 +435,7 @@ name = "pluggy" version = "1.3.0" requires_python = ">=3.8" summary = "plugin and hook calling mechanisms for python" +groups = ["dev"] files = [ {file = "pluggy-1.3.0-py3-none-any.whl", hash = "sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7"}, {file = "pluggy-1.3.0.tar.gz", hash = "sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12"}, @@ -419,6 +446,7 @@ name = "pygments" version = "2.17.2" requires_python = ">=3.7" summary = "Pygments is a syntax highlighting package written in Python." +groups = ["default", "dev"] files = [ {file = "pygments-2.17.2-py3-none-any.whl", hash = "sha256:b27c2826c47d0f3219f29554824c30c5e8945175d888647acd804ddd04af846c"}, {file = "pygments-2.17.2.tar.gz", hash = "sha256:da46cec9fd2de5be3a8a784f434e4c4ab670b4ff54d605c4c2717e9d49c4c367"}, @@ -429,6 +457,7 @@ name = "pyproject-hooks" version = "1.0.0" requires_python = ">=3.7" summary = "Wrappers to call pyproject.toml-based build backend hooks." +groups = ["dev"] dependencies = [ "tomli>=1.1.0; python_version < \"3.11\"", ] @@ -442,6 +471,7 @@ name = "pytest" version = "7.4.3" requires_python = ">=3.7" summary = "pytest: simple powerful testing with Python" +groups = ["dev"] dependencies = [ "colorama; sys_platform == \"win32\"", "exceptiongroup>=1.0.0rc8; python_version < \"3.11\"", @@ -460,6 +490,7 @@ name = "pytest-mock" version = "3.12.0" requires_python = ">=3.8" summary = "Thin-wrapper around the mock package for easier use with pytest" +groups = ["dev"] dependencies = [ "pytest>=5.0", ] @@ -473,6 +504,7 @@ name = "python-dotenv" version = "1.0.0" requires_python = ">=3.8" summary = "Read key-value pairs from a .env file and set them as environment variables" +groups = ["dev"] files = [ {file = "python-dotenv-1.0.0.tar.gz", hash = "sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba"}, {file = "python_dotenv-1.0.0-py3-none-any.whl", hash = "sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a"}, @@ -483,6 +515,7 @@ name = "requests" version = "2.31.0" requires_python = ">=3.7" summary = "Python HTTP for Humans." +groups = ["dev"] dependencies = [ "certifi>=2017.4.17", "charset-normalizer<4,>=2", @@ -499,6 +532,7 @@ name = "requests-toolbelt" version = "1.0.0" requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" summary = "A utility belt for advanced users of python-requests" +groups = ["dev"] dependencies = [ "requests<3.0.0,>=2.0.1", ] @@ -511,6 +545,7 @@ files = [ name = "resolvelib" version = "1.0.1" summary = "Resolve abstract dependencies into concrete ones" +groups = ["dev"] files = [ {file = "resolvelib-1.0.1-py2.py3-none-any.whl", hash = "sha256:d2da45d1a8dfee81bdd591647783e340ef3bcb104b54c383f70d422ef5cc7dbf"}, {file = "resolvelib-1.0.1.tar.gz", hash = "sha256:04ce76cbd63fded2078ce224785da6ecd42b9564b1390793f64ddecbe997b309"}, @@ -521,6 +556,7 @@ name = "rich" version = "13.7.0" requires_python = ">=3.7.0" summary = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" +groups = ["default", "dev"] dependencies = [ "markdown-it-py>=2.2.0", "pygments<3.0.0,>=2.13.0", @@ -536,6 +572,7 @@ name = "shellingham" version = "1.5.4" requires_python = ">=3.7" summary = "Tool to Detect Surrounding Shell" +groups = ["dev"] files = [ {file = "shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686"}, {file = "shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de"}, @@ -546,6 +583,8 @@ name = "tomli" version = "2.0.1" requires_python = ">=3.7" summary = "A lil' TOML parser" +groups = ["dev"] +marker = "python_version < \"3.11\"" files = [ {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, @@ -556,6 +595,7 @@ name = "tomlkit" version = "0.12.3" requires_python = ">=3.7" summary = "Style preserving TOML library" +groups = ["dev"] files = [ {file = "tomlkit-0.12.3-py3-none-any.whl", hash = "sha256:b0a645a9156dc7cb5d3a1f0d4bab66db287fcb8e0430bdd4664a095ea16414ba"}, {file = "tomlkit-0.12.3.tar.gz", hash = "sha256:75baf5012d06501f07bee5bf8e801b9f343e7aac5a92581f20f80ce632e6b5a4"}, @@ -566,6 +606,8 @@ name = "truststore" version = "0.8.0" requires_python = ">= 3.10" summary = "Verify certificates using native system trust stores" +groups = ["dev"] +marker = "python_version >= \"3.10\"" files = [ {file = "truststore-0.8.0-py3-none-any.whl", hash = "sha256:e37a5642ae9fc48caa8f120b6283d77225d600d224965a672c9e8ef49ce4bb4c"}, {file = "truststore-0.8.0.tar.gz", hash = "sha256:dc70da89634944a579bfeec70a7a4523c53ffdb3cf52d1bb4a431fda278ddb96"}, @@ -576,6 +618,8 @@ name = "typing-extensions" version = "4.9.0" requires_python = ">=3.8" summary = "Backported and Experimental Type Hints for Python 3.8+" +groups = ["default", "dev"] +marker = "python_version < \"3.9\"" files = [ {file = "typing_extensions-4.9.0-py3-none-any.whl", hash = "sha256:af72aea155e91adfc61c3ae9e0e342dbc0cba726d6cba4b6c72c1f34e47291cd"}, {file = "typing_extensions-4.9.0.tar.gz", hash = "sha256:23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783"}, @@ -586,6 +630,7 @@ name = "unearth" version = "0.12.1" requires_python = ">=3.7" summary = "A utility to fetch and download python packages" +groups = ["dev"] dependencies = [ "packaging>=20", "requests>=2.25", @@ -600,6 +645,7 @@ name = "urllib3" version = "2.1.0" requires_python = ">=3.8" summary = "HTTP library with thread-safe connection pooling, file post, and more." +groups = ["dev"] files = [ {file = "urllib3-2.1.0-py3-none-any.whl", hash = "sha256:55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3"}, {file = "urllib3-2.1.0.tar.gz", hash = "sha256:df7aa8afb0148fa78488e7899b2c59b5f4ffcfa82e6c54ccb9dd37c1d7b52d54"}, @@ -610,6 +656,7 @@ name = "virtualenv" version = "20.25.0" requires_python = ">=3.7" summary = "Virtual Python Environment builder" +groups = ["dev"] dependencies = [ "distlib<1,>=0.3.7", "filelock<4,>=3.12.2", @@ -625,6 +672,8 @@ name = "zipp" version = "3.17.0" requires_python = ">=3.8" summary = "Backport of pathlib-compatible object wrapper for zip files" +groups = ["dev"] +marker = "python_version < \"3.10\"" files = [ {file = "zipp-3.17.0-py3-none-any.whl", hash = "sha256:0e923e726174922dce09c53c59ad483ff7bbb8e572e00c7f7c46b88556409f31"}, {file = "zipp-3.17.0.tar.gz", hash = "sha256:84e64a1c28cf7e91ed2078bb8cc8c259cb19b76942096c8d7b84947690cabaf0"}, diff --git a/src/pdm_download/command.py b/src/pdm_download/command.py index 3fd5a62..b6e1da4 100644 --- a/src/pdm_download/command.py +++ b/src/pdm_download/command.py @@ -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 @@ -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 @@ -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: