diff --git a/piptools/repositories/pypi.py b/piptools/repositories/pypi.py index 41230f696..48d6614de 100644 --- a/piptools/repositories/pypi.py +++ b/piptools/repositories/pypi.py @@ -389,6 +389,9 @@ def _get_matching_candidates( return candidates_by_version[matching_versions[0]] def _get_file_hash(self, link: Link) -> str: + if link.hash_name == FAVORITE_HASH: + log.debug(f"Getting hash from link {link.show_url}") + return ":".join([FAVORITE_HASH, link.hash]) log.debug(f"Hashing {link.show_url}") h = hashlib.new(FAVORITE_HASH) with open_local_or_remote_file(link, self.session) as f: 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()