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

Hash packages without unpacking (Fixes #512 and #544) #557

Merged
merged 3 commits into from
Sep 27, 2017

Conversation

suutari
Copy link
Contributor

@suutari suutari commented Sep 2, 2017

The PyPIRepository._get_file_hash used to call unpack_url, when
generating the hash. It only needed the side effect of the downloaded
package being left in the download directory and the unpacking part was
actually unnecessary. Change it to just open the (local or remote)
package as a file object and hash the contents without unpacking.

This makes it faster and lighter, since unpacking consumes CPU cycles
and disk space, and more importantly, avoids problems which happen when
some distribution has a file with the same name as a directory in
another. Unpacking both to packages to the same directory will then
fail. E.g. matplotlib-2.0.2.tar.gz has a directory named LICENSE, but
many other packages have a file named LICENSE.

Fixes #512, #544

Contributor checklist
  • Provided the tests for the changes (Thanks @mete0r)
  • Added the changes to CHANGELOG.md
  • Requested (or received) a review from another contributor

Some distributions have incompatible type of files with same name
on the root directory. For example, matplotlib-2.0.2.tar.gz has a
directory named "LICENSE" on the root, which may conflict many
other distributions, causing errors like:

  IOError: [Errno 20] Not a directory: u'/tmp/tmpz/LICENSE/LICENSE_STIX'

So we need to isolate unpacking directory of each distributions.
@suutari suutari force-pushed the dont-unpack-for-hashing branch from 1b9fec8 to e264bd3 Compare September 2, 2017 14:36
The PyPIRepository._get_file_hash used to call unpack_url, when
generating the hash.  It only needed the side effect of the downloaded
package being left in the download directory and the unpacking part was
actually unnecessary.  Change it to just open the (local or remote)
package as a file object and hash the contents without unpacking.

This makes it faster and lighter, since unpacking consumes CPU cycles
and disk space, and more importantly, avoids problems which happen when
some distribution has a file with the same name as a directory in
another.  Unpacking both to packages to the same directory will then
fail.  E.g. matplotlib-2.0.2.tar.gz has a directory named LICENSE, but
many other packages have a file named LICENSE.

Fixes jazzband#512, jazzband#544
@suutari suutari force-pushed the dont-unpack-for-hashing branch from e264bd3 to 627dbaf Compare September 2, 2017 14:36
@suutari suutari changed the title Dont unpack for hashing (Fixes #512 and #544) Hash packages without unpacking (Fixes #512 and #544) Sep 2, 2017
Copy link
Contributor

@davidovich davidovich left a comment

Choose a reason for hiding this comment

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

LGTM

@suutari
Copy link
Contributor Author

suutari commented Sep 16, 2017

Can this be merged, please?

@graingert
Copy link
Member

@suutari it would be even better if you pulled the SHA256 hashes from PyPI directly.

@graingert
Copy link
Member

Fixes #544

@graingert
Copy link
Member

@suutari have a look at #543 too.

@suutari-ai
Copy link
Contributor

IMHO Pulling the hashesh from Warehouse is a different issue. This fixes two existing bugs. That would be a new feature, so I'd rather create a new PR of it.

@lily-mara
Copy link

This would also help solve sdispater/poet#21 - which is basically an extension of #512. It would be great to see this merged.

@vphilippon
Copy link
Member

@suutari @suutari-ai Could you rebase on master, I'll be ready to get this in right away. Thanks!

@vphilippon vphilippon merged commit dc261ed into jazzband:master Sep 27, 2017
@vphilippon
Copy link
Member

Thanks for the PR!

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.

6 participants