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

Cache hashes for --generate-hashes #641

Merged
merged 1 commit into from
Mar 19, 2018
Merged

Conversation

justicz
Copy link

@justicz justicz commented Mar 8, 2018

Improves the speed of pip-compile --generate-hashes by caching the hashes we already have.

If hashes for a particular dependency have already been generated, and are available in the output file, this PR skips pulling all of the packages again from PyPI, dramatically increasing the speed of pip-compile when the --generate-hashes flag is passed.

This has the added benefit of improving security; if pip-compile --generate-hashes is run regularly as part of a build pipeline, hashes will be guaranteed stay the same unless the version has been explicitly updated.

Helps resolve #521

Maintainer Edit - Changelog:
Improved the speed of pip-compile --generate-hashes by caching the hashes from an existing output file.

@justicz justicz force-pushed the master branch 3 times, most recently from 2a7a757 to 86a15d4 Compare March 12, 2018 14:56
@vphilippon vphilippon self-requested a review March 19, 2018 17:18
@vphilippon vphilippon added this to the 1.12.0 milestone Mar 19, 2018
Copy link
Member

@vphilippon vphilippon left a comment

Choose a reason for hiding this comment

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

Tested: Works and improved speed greatly with --generate-hashes.
LGTM 👍

@vphilippon vphilippon merged commit 168f0da into jazzband:master Mar 19, 2018
@vphilippon
Copy link
Member

Thanks for that first contribution @justicz, nice work!

@graingert
Copy link
Member

does this include the new hash of the new wheel in the case that someone uploads a .tar.gz, then later a wheel?

@justicz
Copy link
Author

justicz commented Mar 19, 2018 via email

@graingert
Copy link
Member

I often hit this scenario. Because I regularly find packages without wheels and I go and poke the maintainer to go release them

@justicz
Copy link
Author

justicz commented Mar 19, 2018

OK. In that particular case, would it be acceptable for you to just delete the hashes in the generated output file for that package? Then they'll just be regenerated the usual, slow way. I would tend to think that this change provides the better UX 99% of the time.

@vphilippon
Copy link
Member

A pip-compile with an existing requirements.txt would not have updated the versions (pins) unless required to, or explicitly told to do so with --upgrade or --upgrade-package. I think this PR actually aligns --generate-hashes with that: No changes unless required or explicitly told to do so.
Now we might want to add and option analog to --upgrade/--upgrade-package regarding hashes. Maybe something like --regenerate-hashes. Manual edits to the compiled requirements.txt can lead to a lot of trouble, and I usually advise against it (warranty void if touched 😛 ) .

(btw @graingert thanks for the observation, and for poking maintainers for wheels too 😄 )

@justicz
Copy link
Author

justicz commented Mar 19, 2018

A pip-compile with an existing requirements.txt would not have updated the versions (pins) unless required to, or explicitly told to do so with --upgrade or --upgrade-package.

Good to know! My mistake, I guess the security benefit I mentioned earlier is actually already the default behavior then?

Edit: Oh, never mind -- I missed that your comment was talking about versions and hash pins separately. In that case, my point about increasing security by not updating hashes still stands I think.

@vphilippon
Copy link
Member

@justicz Your point on increased security sounds right to me, but don't quote me on this, I don't consider myself enough of a security guy to argue that it's better or worse in terms of security.
What I can say though is that I prefer this new behavior regarding how and when the requirements.txt and its content gets to be modified by a pip-compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pip-compile with generate hashes is very slow
3 participants