From c1789cf846fd685bbd11b639c57d943ef4f36265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=A4ufl?= Date: Fri, 19 Aug 2022 15:46:39 +0200 Subject: [PATCH] Get hash from link --- piptools/repositories/pypi.py | 2 ++ tests/test_repository_pypi.py | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/piptools/repositories/pypi.py b/piptools/repositories/pypi.py index 41230f696..20bfc643e 100644 --- a/piptools/repositories/pypi.py +++ b/piptools/repositories/pypi.py @@ -390,6 +390,8 @@ def _get_matching_candidates( def _get_file_hash(self, link: Link) -> str: log.debug(f"Hashing {link.show_url}") + if link.hash_name == FAVORITE_HASH: + return ":".join([FAVORITE_HASH, link.hash]) h = hashlib.new(FAVORITE_HASH) with open_local_or_remote_file(link, self.session) as f: # Chunks to iterate diff --git a/tests/test_repository_pypi.py b/tests/test_repository_pypi.py index cb08ec5fd..be98e41e7 100644 --- a/tests/test_repository_pypi.py +++ b/tests/test_repository_pypi.py @@ -68,6 +68,19 @@ def test_get_file_hash_without_interfering_with_each_other(from_line, pypi_repos ) +def test_get_file_hash_from_link(pypi_repository): + assert ( + pypi_repository._get_file_hash( + Link( + "https://example.com/simple/click/8.1.3/" + "click-8.1.3-py3-none-any.whl" + "#sha256=bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48" + ) + ) + == "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48" + ) + + def test_get_hashes_editable_empty_set(from_editable, pypi_repository): ireq = from_editable("git+https://github.com/django/django.git#egg=django") assert pypi_repository.get_hashes(ireq) == set()