Skip to content

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

Merged
merged 1 commit into from
Aug 14, 2019

Conversation

sbidoul
Copy link
Member

@sbidoul sbidoul commented Aug 13, 2019

This follows #6853 (comment)

cc/ @cjerdonek

@sbidoul sbidoul force-pushed the clarify-autobuilding-sbi branch from 3c54b68 to 06b9529 Compare August 13, 2019 12:38

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),
Copy link
Member

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?

Copy link
Member Author

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)
Copy link
Member

@cjerdonek cjerdonek Aug 13, 2019

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):

wheel_cache = WheelCache(options.cache_dir, options.format_control)

PPS - wheel also seems to set it.

Copy link
Member Author

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:

finder=Mock(), preparer=Mock(), wheel_cache=None,

Copy link
Member Author

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.

Copy link
Member

@cjerdonek cjerdonek left a 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.

@@ -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
Copy link
Member

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.

Copy link
Member

@cjerdonek cjerdonek Aug 13, 2019

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.

Copy link
Member Author

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.
"""
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@cjerdonek cjerdonek Aug 14, 2019

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.

@pradyunsg pradyunsg changed the title clarify WheelBuilder.build() a bit Clarify WheelBuilder.build() a bit Aug 14, 2019
@pradyunsg pradyunsg added C: wheel The wheel format and 'pip wheel' command type: refactor Refactoring code labels Aug 14, 2019
@sbidoul
Copy link
Member Author

sbidoul commented Aug 14, 2019

I also added a couple of clarification comments in should_use_ephemeral_cache.

Also I'm thinking that, inside should_use_ephemeral_cache, not should_unpack would be better named must_build, in slight anticipation of what we'll do next.

@cjerdonek cjerdonek added the skip news Does not need a NEWS file entry (eg: trivial changes) label Aug 14, 2019
Copy link
Member

@cjerdonek cjerdonek left a comment

Choose a reason for hiding this comment

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

Great!

@cjerdonek
Copy link
Member

Also I'm thinking that, inside should_use_ephemeral_cache, not should_unpack would be better named must_build, in slight anticipation of what we'll do next.

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).

@sbidoul
Copy link
Member Author

sbidoul commented Aug 14, 2019

Were you saying you wanted to do this now, or were you referencing what you wanted to do in the other PR?

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.

@sbidoul sbidoul force-pushed the clarify-autobuilding-sbi branch from ab9f7dd to ea517a2 Compare August 14, 2019 09:24
@sbidoul
Copy link
Member Author

sbidoul commented Aug 14, 2019

I squashed the commits. Ready to merge.

@cjerdonek
Copy link
Member

see if you had an opinion on that name.

Yeah, that seems like a good name. 👍

@cjerdonek
Copy link
Member

cjerdonek commented Aug 14, 2019

Thanks again! 👍

@cjerdonek cjerdonek merged commit c2cf232 into pypa:master Aug 14, 2019
@cjerdonek
Copy link
Member

Also I'm thinking that, inside should_use_ephemeral_cache, not should_unpack would be better named must_build, in slight anticipation of what we'll do next.

Maybe build() should also grow an additional argument like that (e.g. build_optional or force_build) since it's orthogonal to whether unpacking should take place. It just so happens that they coincide (or don't coincide), depending on how you look at it.

@sbidoul sbidoul deleted the clarify-autobuilding-sbi branch August 14, 2019 10:59
@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Sep 13, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Sep 13, 2019
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 C: wheel The wheel format and 'pip wheel' command 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