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

Use wheelfile-based pkg_resources.Distribution for metadata #7539

Merged
merged 5 commits into from
Jan 5, 2020

Conversation

chrahunt
Copy link
Member

@chrahunt chrahunt commented Jan 2, 2020

Use wheel-file-based pkg_resources.Distribution for metadata

Adapts the zipfile-compatible wheel metadata functions from #7538 to back a pkg_resources.Distribution. This allows us to remove wheel file unpacking everywhere except right before installation.

Progresses #6030 and implements simplification described in #7483 (comment).

@chrahunt chrahunt added type: refactor Refactoring code skip news Does not need a NEWS file entry (eg: trivial changes) labels Jan 2, 2020
@chrahunt chrahunt changed the title Refactor/get dist from zip Use wheelfile-based pkg_resources.Distribution for metadata Jan 2, 2020
@pradyunsg
Copy link
Member

@-me when this is ready for review. :)

@chrahunt chrahunt marked this pull request as ready for review January 2, 2020 13:45
Copy link
Member

@sbidoul sbidoul left a comment

Choose a reason for hiding this comment

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

Very nice. Code LGTM.

As this should improve performance with large wheels, this could be mentioned in a news file?

One can probably also remove the unpack_file in the preparer if link.is_wheel (in a followup)?

# unpack the archive to the build dir location. even when only
# downloading archives, they have to be unpacked to parse dependencies
unpack_file(from_path, location, content_type)

src/pip/_internal/utils/wheel.py Outdated Show resolved Hide resolved
tests/lib/__init__.py Outdated Show resolved Hide resolved
@chrahunt
Copy link
Member Author

chrahunt commented Jan 3, 2020

As this should improve performance with large wheels, this could be mentioned in a news file?

It should for pip wheel. I would mention it after removing the now-unnecessary unpack_file you mentioned, since otherwise the "if"s and "except"s in the news entry here would make it too wordy.

pkg_resources.Distribution classes delegate to the IMetadataProvider
implementation provided at construction. This is the one we'll use for
adapting a ZipFile to pkg_resources.DistInfoDistribution.
Copy link
Member

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

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

LGTM.

Feel free to merge if you want to -- these comments aren't blockers.

There's another spot where we do unconditional unpacking, as @sbidoul has helpfully pointed out too. I would've preferred to change that too, in this PR since we're already removing one unnecessary location where we're unpacking -- but doing it in a follow up wouldn't hurt either. :)

Thanks for breaking this up into smaller PRs that were independently reviewed. :)

src/pip/_internal/wheel_builder.py Show resolved Hide resolved
src/pip/_internal/distributions/wheel.py Show resolved Hide resolved
src/pip/_internal/utils/pkg_resources.py Show resolved Hide resolved
tests/functional/test_install_wheel.py Outdated Show resolved Hide resolved
@chrahunt
Copy link
Member Author

chrahunt commented Jan 5, 2020

There's another spot where we do unconditional unpacking, as @sbidoul has helpfully pointed out too. I would've preferred to change that too, in this PR since we're already removing one unnecessary location where we're unpacking -- but doing it in a follow up wouldn't hurt either. :)

I would have, but I wanted to move all unpacking out of the individual "unpack_*" functions in operations.prepare (and rename them) before that, to avoid making that code worse. :)

Copy link
Member

@sbidoul sbidoul left a comment

Choose a reason for hiding this comment

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

Tested again, works fine. 👍

tests/functional/test_install_wheel.py Outdated Show resolved Hide resolved
We now extract all metadata files from the wheel directly into memory
and make them available to the wrapping pkg_resources.Distribution via
the DictMetadata introduced earlier.
Actual installation has been using the wheel file directly for some
time. The last piece that required an unpacked wheel was metadata. Now
that it uses the wheel file directly, we can remove the unpacking after
build.
@chrahunt chrahunt merged commit b7ed044 into pypa:master Jan 5, 2020
@chrahunt chrahunt deleted the refactor/get-dist-from-zip branch January 5, 2020 17:24
@chrahunt
Copy link
Member Author

chrahunt commented Jan 5, 2020

Thank you both for reviewing.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Feb 4, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Feb 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation skip news Does not need a NEWS file entry (eg: trivial changes) type: refactor Refactoring code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants