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

Fix bug background workunits were printed in UI #7997

Merged

Conversation

cattibrie
Copy link
Contributor

Problem

Background workunits were present in UI output. The reason is that background root workunit start to have a parent - main thread root.

Solution

Print workunit label in UI only if it is not under the background root workunit.

@@ -246,6 +246,18 @@ def root(self):
ret = ret.parent
return ret

def is_background(self, background_root_workunit):
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend using a keyword only arg here, so that callers must use a kwarg.

Suggested change
def is_background(self, background_root_workunit):
def is_background(self, *, background_root_workunit):

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This is a required parameter of a particular type, rather than a boolean or optional parameter. So I'm not sure I agree in this case.

But @cattibrie : it would be good to add a docstring for this method.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Eric-Arellano Is it likely to ever accept more than one argument? I think that if not (it seems not), then a positional param seems ok (with a docstring, as above).

Copy link
Contributor

Choose a reason for hiding this comment

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

Eh after typing up the below example, I agree that yes it's fine to not use kwarg only here:

lint_workunit.is_background(compile_workunit)
lint_workunit.is_background(background_root_workunit=compile_workunit)

--

However, in general, want to respond to this:

This is a required parameter of a particular type, rather than a boolean or optional parameter.

True, but there is often (not always) value in enforcing kwarg only for required parameters too. For example, from strutil.py:

def strip_prefix(string: str, prefix: str) -> str: ...

strip_prefix("hello world", "hello")
strip_prefix("hello world", prefix="hello")

You can of course figure it out with the first version, but the second has no ambiguity and I would argue is worth the extra few characters.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

@Eric-Arellano : If the arguments had different types, explicitly naming them would be slightly less valuable though: that's what I was referring to here.

Copy link
Sponsor Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -246,6 +246,18 @@ def root(self):
ret = ret.parent
return ret

def is_background(self, background_root_workunit):
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This is a required parameter of a particular type, rather than a boolean or optional parameter. So I'm not sure I agree in this case.

But @cattibrie : it would be good to add a docstring for this method.

"""
:API: public
"""
ret = self
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @cattibrie !

nit: let's rename ret (to curr_workunit?), since it no longer carries the meaning of the possible return value, unlike the methods above.

@cattibrie cattibrie force-pushed the etyurina/background_workunits_in_ui branch from af0a10b to 4c2f332 Compare July 3, 2019 10:43
@illicitonion illicitonion merged commit 1d5b343 into pantsbuild:master Jul 4, 2019
cosmicexplorer added a commit to cosmicexplorer/pants that referenced this pull request Jul 14, 2019
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.

None yet

6 participants