-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Clarify WheelBuilder.build() a bit #6869
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
Conversation
3c54b68
to
06b9529
Compare
src/pip/_internal/wheel.py
Outdated
|
||
for req in requirements: | ||
ephem_cache = should_use_ephemeral_cache( | ||
req, format_control=format_control, autobuilding=autobuilding, | ||
cache_available=cache_available, | ||
cache_available=bool(self.wheel_cache.cache_dir), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure the wheel cache is available at all call sites?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pradyunsg goog catch. A unit test caught it too. Fixed.
buildset = [] | ||
format_control = self.finder.format_control | ||
# Whether a cache directory is available for autobuilding=True. | ||
cache_available = bool(self._wheel_dir or self.wheel_cache.cache_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this was working before without first checking that self.wheel_cache
is truthy, does this mean we can add the following to the above asserts?
if autobuilding:
assert self.wheel_cache
(or add and self.wheel_cache
to the first expression of your existing assert)
PS - here is where install
sets wheel_cache
(unconditionally):
pip/src/pip/_internal/commands/install.py
Line 318 in 76a8954
wheel_cache = WheelCache(options.cache_dir, options.format_control) |
PPS - wheel
also seems to set it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The failing test was due to this mock providing no wheelcache:
Line 700 in 76a8954
finder=Mock(), preparer=Mock(), wheel_cache=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I fixed the test instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for filing the PR! A couple minor comments.
src/pip/_internal/wheel.py
Outdated
@@ -1036,14 +1037,22 @@ def build( | |||
# type: (...) -> List[InstallRequirement] | |||
"""Build wheels. | |||
|
|||
:param unpack: If True, replace the sdist we built from with the | |||
newly built wheel, in preparation for installation. | |||
:param autobuilding: If True, replace the sdist we built from with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than making this change, how about using this PR also as an opportunity to rename autobuilding
to something more self-descriptive like should_unpack
(as I suggested here). That way the argument better describes what it does and will better match the semantics of what we want going forward. (And judging by the docstring, it looks like the original author was thinking about using something like that as the name, too, anyways.) The word "auto-building" still seems confusing to me. :) Also, I'm suggesting should_unpack
rather than e.g. unpack
because it will be a unique string in the code base, making it easy to search.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, maybe the argument description can be clarified to say "If True, after building the wheel, unpack it and replace the sdist with the unpacked version in preparation for installation." That way it's clear that not just the replacement but also the unpacking only happens if the argument is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
:param unpack: If True, replace the sdist we built from with the | ||
newly built wheel, in preparation for installation. | ||
:param autobuilding: If True, replace the sdist we built from with the | ||
unpacked newly built wheel, in preparation for installation. | ||
:return: True if all the wheels built correctly. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that you've changed the test to fix all call sites, how about adding assert self.wheel_cache
to the beginning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not do it so far because I figured it was obvious enough that wheel_cache was a mandatory argument of the WheelBuilder constructor (per the typing declaration), and in case one makes the error, the crash reason will be as easy to understand as an assert. So I thought an additional assert about that would have little additional information value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I thought an additional assert about that would have little additional information value.
I wouldn't say it adds little value as I do think it helps people reading the code. (Case in point: it would have answered @pradyunsg's question.) But I agree it's redundant with the type annotation, so I'm okay with leaving it out.
I also added a couple of clarification comments in Also I'm thinking that, inside |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Were you saying you wanted to do this now, or were you referencing what you wanted to do in the other PR? As that change is limited to just one function, maybe it would be okay to do it as part of the other PR (and since I'd be okay merging this one now). |
I had no preference about that. It was more a mention to hint at what I have in mind for the other PR and see if you had an opinion on that name. |
ab9f7dd
to
ea517a2
Compare
I squashed the commits. Ready to merge. |
Yeah, that seems like a good name. 👍 |
Thanks again! 👍 |
Maybe |
This follows #6853 (comment)
cc/ @cjerdonek