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

Improve formatting of ./pants goals and ./pants target-types2 #9414

Merged
merged 7 commits into from
Mar 31, 2020

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Mar 28, 2020

Before:

Screen Shot 2020-03-28 at 11 32 08 AM

Screen Shot 2020-03-28 at 11 31 34 AM

After:

Screen Shot 2020-03-30 at 9 47 05 AM

Screen Shot 2020-03-30 at 9 47 42 AM

# Delete this line to force CI to run Clippy and the Rust tests.
[ci skip-rust-tests]  # No Rust changes made.

# Delete this line to force CI to run the JVM tests.
[ci skip-jvm-tests]  # No JVM changes made.

# Delete this line to force CI to run the JVM tests.
[ci skip-jvm-tests]  # No JVM changes made.
# Delete this line to force CI to run Clippy and the Rust tests.
[ci skip-rust-tests]  # No Rust changes made.

# Delete this line to force CI to run the JVM tests.
[ci skip-jvm-tests]  # No JVM changes made.

# Delete this line to force CI to run the JVM tests.
[ci skip-jvm-tests]  # No JVM changes made.
# Delete this line to force CI to run Clippy and the Rust tests.
[ci skip-rust-tests]  # No Rust changes made.

# Delete this line to force CI to run the JVM tests.
[ci skip-jvm-tests]  # No JVM changes made.
Copy link
Contributor Author

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

A downside of this PR is that the output of both goals is now 3x longer and ./pants goals no longer fits on my terminal without scrolling.

But, I think the gains in readability are worth it. The biggest thing I wanted to get rid of was using rjust() because it makes it difficult to quickly scan all the goal and target type names.

@benjyw
Copy link
Contributor

benjyw commented Mar 29, 2020

We could still have the shorter goals output but left-justify the goal name. I think that might be better.

[ci skip-jvm-tests]  # No JVM changes made.
[ci skip-rust-tests]
# Delete this line to force CI to run the JVM tests.
[ci skip-jvm-tests]  # No JVM changes made.
@Eric-Arellano
Copy link
Contributor Author

We could still have the shorter goals output but left-justify the goal name. I think that might be better.

Good call. That looks better.

--

I think I want to add line wrapping of the descriptions before merging this. The soft wrapping makes the first "after" picture not look great.

Without this, several `goal` descriptions use soft wrapping, which puts a bunch of noise in the left column which is supposed to solely be the name of goals and target types.

# Delete this line to force CI to run Clippy and the Rust tests.
[ci skip-rust-tests]  # No Rust changes made.

# Delete this line to force CI to run the JVM tests.
[ci skip-jvm-tests]  # No JVM changes made.
@Eric-Arellano
Copy link
Contributor Author

Here's a 3rd option, which I think is my favorite. Tries to strike a balance between readability vs. compactness.

Screen Shot 2020-03-30 at 8 02 54 AM

Thoughts?

@herman5
Copy link
Member

herman5 commented Mar 30, 2020

I find Option 3 to be the most visually pleasing, and worth the cost of extra space. My eyes can easily navigate it whereas the previous option's right-indent when wrapping on a new line felt unexpected - it didn't read like typical everyday copy.

@pierrechevalier83
Copy link
Contributor

Here's a 3rd option, which I think is my favorite. Tries to strike a balance between readability vs. compactness.

Screen Shot 2020-03-30 at 8 02 54 AM

Thoughts?

I personally like that 3rd option more than the alternatives, but I wouldn't be massively anal if anyone disagreed strongly enough.

…on indentation

Also, stop using () with target types, e.g. `files()` -> `files`. Pierre pointed out that this was confusing because you can't type `./pants target-types2 --details=files()`.

# Delete this line to force CI to run Clippy and the Rust tests.
[ci skip-rust-tests]  # No Rust changes made.

# Delete this line to force CI to run the JVM tests.
[ci skip-jvm-tests]  # No JVM changes made.
Copy link
Contributor

@pierrechevalier83 pierrechevalier83 left a comment

Choose a reason for hiding this comment

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

Sorry, didn't get to finish the review so just sharing a couple of comments for now.

chars_before_description = longest_target_alias + 2
alias = console.cyan(f"{self.alias}".ljust(chars_before_description))
if not self.description:
description = "<no description>"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I love this. Maybe empty would look more user friendly. Here in a way it feels like punishing the user of the tool for the developer not taking the time to provide a description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sgtm, I agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, hm, @gshuflin explicitly added this feature in #8088 and I remember it confused him why something was blank, e.g. wondering if it was a bug in Pants.

I would rather that we place a higher burden on us Pants devs to ensure we're writing good generated documentation. For example, when adding a new goal, we should expect Pants devs to put a screenshot of how it renders in ./pants goals.

One benefit of <no description> is that it's uglier than a blank line, so it motivates us Pants devs to do something. Specifically because of seeing <no description>, I've added docstring to two goals in the past two months. I probably would have done nothing if it were just an empty line.

name = name.ljust(chars_before_description)
if self._use_color:
name = cyan(name)
description_lines = textwrap.wrap(description, 80 - chars_before_description)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer for this 80 to be demagicked

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One followup PR I'm planning is to add a util so that it's easy for us to consistently wrap exception messages, whereas we currently almost always use soft wrapping. I've changed my mind that I now think hard wrapping is a better UX in a CLI app than soft wrapping.

I think we'd want the 80 demagicking to happen in that PR. Right now, we're duplicating 80 in 2 places, and once I add ./pants backends, 3 places. Imo, it's premature to factor out the 80 constant without also factoring out the overall wrapping mechanism in a followup.

@Eric-Arellano Eric-Arellano requested a review from gshuflin March 30, 2020 18:24
@Eric-Arellano Eric-Arellano merged commit ae0184c into pantsbuild:master Mar 31, 2020
@Eric-Arellano Eric-Arellano deleted the better-goals branch March 31, 2020 21:40
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.

5 participants