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

Read rez-pip version from distribution metadata #53

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/rez_pip/download.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
import typing
import asyncio
import hashlib
Expand All @@ -8,6 +9,11 @@
import aiohttp
import rich.progress

if sys.version_info >= (3, 10):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata

import rez_pip.pip

_LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -105,7 +111,7 @@ async def _download(
package.download_info.url,
headers={
"Content-Type": "application/octet-stream",
"User-Agent": "rez-pip/0.1.0",
"User-Agent": f"rez-pip/{importlib_metadata.version('rez-pip')}",
},
) as response:
size = int(response.headers.get("content-length", 0))
Expand Down
31 changes: 21 additions & 10 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@
else:
from unittest import mock

if sys.version_info >= (3, 10):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata

import pytest
import aiohttp

import rez_pip.pip
import rez_pip.download


@pytest.fixture(scope="module", autouse=True)
def rezPipVersion():
with mock.patch.object(importlib_metadata, "version", return_value="1.2.3.4.5"):
yield


@pytest.mark.parametrize(
"packages",
[
Expand Down Expand Up @@ -79,7 +90,7 @@ def test_download(packages: typing.Dict[str, str], tmp_path: pathlib.Path):
f"https://example.com/{package}.whl",
headers={
"Content-Type": "application/octet-stream",
"User-Agent": "rez-pip/0.1.0",
"User-Agent": "rez-pip/1.2.3.4.5",
},
)
for package in packages
Expand Down Expand Up @@ -151,14 +162,14 @@ def test_download_multiple_packages_with_failure(tmp_path: pathlib.Path):
"https://example.com/package-a",
headers={
"Content-Type": "application/octet-stream",
"User-Agent": "rez-pip/0.1.0",
"User-Agent": "rez-pip/1.2.3.4.5",
},
),
mock.call(
"https://example.com/package-b",
headers={
"Content-Type": "application/octet-stream",
"User-Agent": "rez-pip/0.1.0",
"User-Agent": "rez-pip/1.2.3.4.5",
},
),
]
Expand Down Expand Up @@ -218,14 +229,14 @@ def test_download_reuse_if_same_hash(tmp_path: pathlib.Path):
"https://example.com/package-a.whl",
headers={
"Content-Type": "application/octet-stream",
"User-Agent": "rez-pip/0.1.0",
"User-Agent": "rez-pip/1.2.3.4.5",
},
),
mock.call(
"https://example.com/package-b.whl",
headers={
"Content-Type": "application/octet-stream",
"User-Agent": "rez-pip/0.1.0",
"User-Agent": "rez-pip/1.2.3.4.5",
},
),
]
Expand Down Expand Up @@ -281,7 +292,7 @@ def test_download_reuse_if_same_hash(tmp_path: pathlib.Path):
"https://example.com/package-c.whl",
headers={
"Content-Type": "application/octet-stream",
"User-Agent": "rez-pip/0.1.0",
"User-Agent": "rez-pip/1.2.3.4.5",
},
),
]
Expand Down Expand Up @@ -345,14 +356,14 @@ def test_download_redownload_if_hash_changes(tmp_path: pathlib.Path):
"https://example.com/package-a.whl",
headers={
"Content-Type": "application/octet-stream",
"User-Agent": "rez-pip/0.1.0",
"User-Agent": "rez-pip/1.2.3.4.5",
},
),
mock.call(
"https://example.com/package-b.whl",
headers={
"Content-Type": "application/octet-stream",
"User-Agent": "rez-pip/0.1.0",
"User-Agent": "rez-pip/1.2.3.4.5",
},
),
]
Expand Down Expand Up @@ -409,14 +420,14 @@ def test_download_redownload_if_hash_changes(tmp_path: pathlib.Path):
"https://example.com/package-a.whl",
headers={
"Content-Type": "application/octet-stream",
"User-Agent": "rez-pip/0.1.0",
"User-Agent": "rez-pip/1.2.3.4.5",
},
),
mock.call(
"https://example.com/package-b.whl",
headers={
"Content-Type": "application/octet-stream",
"User-Agent": "rez-pip/0.1.0",
"User-Agent": "rez-pip/1.2.3.4.5",
},
),
]
Expand Down