Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apply review feedback, hash is optional
Browse files Browse the repository at this point in the history
radoering committed Nov 19, 2023

Verified

This commit was signed with the committer’s verified signature.
radoering Randy Döring
1 parent 09b8bab commit f1a49e5
Showing 2 changed files with 24 additions and 14 deletions.
28 changes: 15 additions & 13 deletions src/poetry/repositories/http_repository.py
Original file line number Diff line number Diff line change
@@ -244,7 +244,7 @@ def _links_to_data(self, links: list[Link], data: PackageInfo) -> dict[str, Any]
f' "{data.version}"'
)
urls = defaultdict(list)
metadata = {}
metadata: dict[str, pkginfo.Distribution] = {}
files: list[dict[str, Any]] = []
for link in links:
if link.yanked and not data.yanked:
@@ -255,24 +255,26 @@ def _links_to_data(self, links: list[Link], data: PackageInfo) -> dict[str, Any]
assert link.metadata_url is not None
response = self.session.get(link.metadata_url)
distribution = pkginfo.Distribution()
assert link.metadata_hash_name is not None
metadata_hash = getattr(hashlib, link.metadata_hash_name)(
response.text.encode()
).hexdigest()

if metadata_hash != link.metadata_hash:
self._log(
f"Metadata file hash ({metadata_hash}) does not match"
f" expected hash ({link.metadata_hash}).",
level="warning",
)
if link.metadata_hash_name is not None:
metadata_hash = getattr(hashlib, link.metadata_hash_name)(
response.text.encode()
).hexdigest()

if metadata_hash != link.metadata_hash:
self._log(
f"Metadata file hash ({metadata_hash}) does not match"
f" expected hash ({link.metadata_hash})."
f" Metadata file for {link.filename} will be ignored.",
level="warning",
)
continue

distribution.parse(response.content)
metadata[link.url] = distribution
except requests.HTTPError:
self._log(
f"Failed to retrieve metadata at {link.metadata_url}",
level="debug",
level="warning",
)

if link.is_wheel:
10 changes: 9 additions & 1 deletion tests/repositories/test_legacy_repository.py
Original file line number Diff line number Diff line change
@@ -183,7 +183,7 @@ def _get_mock(url: str, **__: Any) -> requests.Response:
response.encoding = "application/text"
response._content = MockRepository.FIXTURES.joinpath(
"metadata", posixpath.basename(url)
).read_bytes()
).read_text().encode()
return response
raise requests.HTTPError()

@@ -206,6 +206,14 @@ def test_get_package_information_pep_658(mocker: MockerFixture) -> None:
assert package.name == "isort-metadata"
assert package.version.text == isort_package.version.text == "4.3.4"
assert package.description == isort_package.description
assert (
package.requires == isort_package.requires == [Dependency("futures", "*")]
)
assert (
str(package.python_constraint)
== str(isort_package.python_constraint)
== ">=2.7,<3.0.dev0 || >=3.4.dev0"
)


def test_get_package_information_skips_dependencies_with_invalid_constraints() -> None:

0 comments on commit f1a49e5

Please sign in to comment.