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

Bring back the fix of #3147 #3213

Merged
merged 1 commit into from
Nov 13, 2018
Merged
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
60 changes: 29 additions & 31 deletions pipenv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,36 +361,6 @@ def get_resolver(self, clear=False, pre=False):
clear_caches=clear, prereleases=pre,
)

def populate_file_hashes(self):
from pipenv.vendor.vistir.compat import Path, to_native_string
from pipenv.vendor.vistir.path import url_to_path

def _should_include(ireq):
# We can only hash artifacts.
try:
if not ireq.link.is_artifact:
return False
except AttributeError:
return False

# But we don't want normal pypi artifcats since the normal resolver
# handles those
if is_pypi_url(ireq.link.url):
return False

# We also don't want to try to hash directories as this will fail
# as these are editable deps and are not hashable.
if (ireq.link.scheme == "file" and
Path(to_native_string(url_to_path(ireq.link.url))).is_dir()):
return False
return True

self.hashes.update({
ireq: self.resolver._hash_cache.get_hash(ireq.link)
for ireq in self.parsed_constraints
if _should_include(ireq)
})

@property
def resolver(self):
if self._resolver is None:
Expand Down Expand Up @@ -421,11 +391,39 @@ def resolve(self):
return self.resolved_tree

def resolve_hashes(self):
def _should_include_hash(ireq):
from pipenv.vendor.vistir.compat import Path, to_native_string
from pipenv.vendor.vistir.path import url_to_path

# We can only hash artifacts.
try:
if not ireq.link.is_artifact:
return False
except AttributeError:
return False

# But we don't want normal pypi artifcats since the normal resolver
# handles those
if is_pypi_url(ireq.link.url):
return False

# We also don't want to try to hash directories as this will fail
# as these are editable deps and are not hashable.
if (ireq.link.scheme == "file" and
Path(to_native_string(url_to_path(ireq.link.url))).is_dir()):
return False
return True

if self.results is not None:
resolved_hashes = self.resolver.resolve_hashes(self.results)
for ireq, ireq_hashes in resolved_hashes.items():
if ireq not in self.hashes:
self.hashes[ireq] = ireq_hashes
if _should_include_hash(ireq):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's right, this works too as an approach, but I actually meant to come back to this because I have some dictionary merging code I implemented in requirementslib which I have plans to use to merge the development lockfile section with the default one:

https://github.com/sarugaku/requirementslib/blob/master/src/requirementslib/models/lockfile.py#L112-L119

https://github.com/sarugaku/requirementslib/blob/master/src/requirementslib/utils.py#L552-L590

I was planning to use the same approach to merge in the hashes from here, but I think we can hold off on that for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, thanks.

self.hashes[ireq] = [
self.resolver.repository._hash_cache.get_hash(ireq.link)
]
else:
self.hashes[ireq] = ireq_hashes
return self.hashes


Expand Down