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

Add help_short field for Python tools and use it to generate the help text #20921

Merged
merged 9 commits into from
May 16, 2024

Conversation

krishnan-chandra
Copy link
Contributor

Closes #20912.

This actually wasn't too bad! I didn't realize the trick with classproperty would work as I intended, but it did. Looking at the individual commits should help separate out the repetitive work (changing help to help_short) from the more substantive changes.

@krishnan-chandra krishnan-chandra changed the title Add python tool help short Add help_short field for Python tools and use it to generate the help text May 14, 2024
@krishnan-chandra
Copy link
Contributor Author

Sample output:

./pants help black
There is no pantsd metadata at /Users/krishnanchandra/Projects/pants/.pants.d/pids/b054a5b87b87/pantsd.
20:02:59.97 [INFO] Initializing scheduler...
20:03:33.31 [INFO] Scheduler initialized.

`black` subsystem options
-------------------------

The Black Python code formatter (https://black.readthedocs.io/).

This version of Pants uses `black` version 23.3.0 by default. Use a dedicated lockfile and the `install_from_resolve` option to control this.

Copy link
Contributor

@huonw huonw 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 doing this separately.

I'd like to get additional eyes on this.

I think @benjyw is probably across this area the most.

docs/notes/2.22.x.md Outdated Show resolved Hide resolved
Comment on lines +53 to +54
# Must be set by subclasses - will be used to set the help text in this class.
help_short: ClassVar[str | Callable[[], str]]
Copy link
Contributor

Choose a reason for hiding this comment

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

I imagine subclasses of PythonToolBase are fairly common for people with their own custom plugins. A search like https://github.com/search?q=pants++PythonToolBase+-path%3A%2Fsrc%5C%2Fpython%5C%2Fpants%5C%2F%2F+-org%3Apantsbuild+language%3Apython&type=code indicates a bunch of ones in open source code.

In a perfect world, we wouldn't break those existing plugins with this change, i.e. so that people can upgrade easily without making changes. My theory is we don't break them, because existing classes will still override help, thus not use this class's version (and thus not read help_short)... but I'm not exactly sure how to verify.

Given I think it should be fine, one approach would be to land it and then see if people report problems.

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

I concur that I think this won't break.

@huonw huonw requested a review from benjyw May 14, 2024 07:01
@huonw
Copy link
Contributor

huonw commented May 14, 2024

@benjyw: background: this comes out of #20901, where @krishnan-chandra added info about the default version of each tool but within the install_from_resolve help text. The desire and change here is to have the info even more obvious as part of the "intro".

The specific implementation approach comes out of the thread #20901 (comment) and in particular the list of options we discussed there:

  1. keep this approach, with a new method on the Subsystem class which lets "leaf" subclasses just set help while still giving superclasses flexibility for manipulating it
  2. a new field manipulated by the Python tool helpers, that Python tool subclasses need to set
  3. a class method that Python tool subclasses can call when formatting their own help text
  4. omit this information about the default version from the subsystem help string and have it just in places that don't cause the subclassing fiddle, i.e. option help text like install_from_resolve.
    1. Variant: omit it for now so we can land this PR with just the parsing & display in option text and no change to the top-level help text, and then consider how to display it elsewhere as follow-up

The original #20901:

  • used option 1 first: added help_extended to Subsystem with a default implementation that deferred directly to help, then the PythonToolRequirementBase overrode it to append additional content to each subclass's help.
  • was cut down to 4i to separate out this more controversial change and thus land Add tool version into install_from_resolve arg documentation #20901 sooner

Thus PR then tries option 2.

Copy link
Sponsor Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

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

Seems like a reasonable approach to me!

@benjyw
Copy link
Sponsor Contributor

benjyw commented May 15, 2024

@huonw I'm fine to merge this but will wait to give you a last say.

Copy link
Contributor

@huonw huonw left a comment

Choose a reason for hiding this comment

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

Really nice, thank you for iterating!

@huonw huonw merged commit 40e8bc9 into pantsbuild:main May 16, 2024
25 checks passed
@krishnan-chandra krishnan-chandra deleted the add-python-tool-help-short branch May 16, 2024 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Python Python backend-related issues category:documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show Python tool versions in top-level help text and documentation
3 participants