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

Fix unnecessary downloads by pipenv lock #3827 #3830

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions news/3827.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed lengthy delays in `pipenv lock`. Use the hash value from the artifact url when available.
33 changes: 20 additions & 13 deletions pipenv/patched/piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def RequirementTracker():
class HashCache(SafeFileCache):
"""Caches hashes of PyPI artifacts so we do not need to re-download them

Hashes are only cached when the URL appears to contain a hash in it and the cache key includes
the hash value returned from the server). This ought to avoid ssues where the location on the
server changes."""
Hashes are only cached when the URL appears to contain a hash in it. We then include
the hash value returned from the server in the cache key. This ought to avoid
issues where the location on the server changes."""
def __init__(self, *args, **kwargs):
session = kwargs.pop('session')
self.session = session
Expand All @@ -65,23 +65,30 @@ def get_hash(self, location):
new_location = copy.deepcopy(location)
if orig_scheme in vcs.all_schemes:
new_location.url = new_location.url.split("+", 1)[-1]
can_hash = new_location.hash
if can_hash:
# hash url WITH fragment

if new_location.hash is not None:
# ignore cache, unless the url contains a hash fragment
hash_value = self.get(new_location.url)
if not hash_value:
hash_value = self._get_file_hash(new_location) if not new_location.url.startswith("ssh") else None
hash_value = hash_value.encode('utf8') if hash_value else None
if can_hash:
self.set(new_location.url, hash_value)
if new_location.hash is not None:
This conversation was marked as resolved.
Show resolved Hide resolved
# only if the url contains a hash
# cache the artifct hash, including the hash fragment in the key
self.set(new_location.url, hash_value)
return hash_value.decode('utf8') if hash_value else None

def _get_file_hash(self, location):
h = hashlib.new(FAVORITE_HASH)
with open_local_or_remote_file(location, self.session) as fp:
for chunk in iter(lambda: fp.read(8096), b""):
h.update(chunk)
return ":".join([FAVORITE_HASH, h.hexdigest()])
if (location.hash is not None
and location.hash_name == FAVORITE_HASH):
hash_value = location.hash
else:
h = hashlib.new(FAVORITE_HASH)
with open_local_or_remote_file(location, self.session) as fp:
for chunk in iter(lambda: fp.read(8096), b""):
h.update(chunk)
hash_value = h.hexdigest()
return ":".join([FAVORITE_HASH, hash_value])


class PyPIRepository(BaseRepository):
Expand Down