Skip to content

Commit

Permalink
Get hash from link
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-k committed Nov 21, 2022
1 parent 6839a64 commit c1789cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions tests/test_repository_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c1789cf

Please sign in to comment.