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

Include provider info in help output for subsystems and target types. #13993

Merged
merged 8 commits into from
Jan 5, 2022

Conversation

kaos
Copy link
Member

@kaos kaos commented Dec 27, 2021

Example output:

$ ./pants help docker
`docker` subsystem options
--------------------------

Options for interacting with Docker.
 
Provider: pants.backend.experimental.docker
Config section: [docker]
 
  --docker-registries="{'key1': val1, 'key2': val2, ...}"
  PANTS_DOCKER_REGISTRIES
  registries
...

$ ./pants help docker_image
`docker_image` target
---------------------

The `docker_image` target describes how to build and tag a Docker image.

[...]

Provider: pants.backend.experimental.docker
Valid fields:

dependencies
    type: Iterable[str] | None
    default: None
    Addresses to other targets that this target depends on, e.g. ['helloworld/subdir:lib'].
...

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]
@kaos kaos requested a review from Eric-Arellano December 27, 2021 14:55
Copy link
Contributor

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

This is awesome! Thanks.

I think this is really useful for the docsite, but I'm not as sure if it's useful for CLI output. With the CLI, you'll only be seeing the help message in the first place if that backend was activated. Wdyt?

I'm wondering if we only want to provide this information in ./pants help-all (JSON), and then in a followup we update our generate_docs.py script to render this info in the docs but we leave it out of ./pants help for now.

--

Another thing to consider is "plugin" fields, like how skip_flake8 is only registered if you use pants.backend.python.lint.flake8, even though the python_source target is registered by pants.backend.python. It would be sweet to store the backend for each Field, so that we can render the backend if its backend != the backend of the original target.

src/python/pants/help/help_formatter.py Outdated Show resolved Hide resolved
@kaos
Copy link
Member Author

kaos commented Dec 27, 2021

I think this is really useful for the docsite, but I'm not as sure if it's useful for CLI output.

Yeah, I thought the docsite generation could come as a follow up. But I still think this is useful from the CLI, either to tell which backend to disable if you want to get rid of some feature, or perhaps more importantly, to identify if a feature comes from a certain plugin or if it is a core pants feature loaded with a backend.

Consider an in-house developed company plugin for pants. Those employees that are not well acquainted with Pants could have a hard time telling which features are added by the plugin and which are core pants features. This helps answer that (and is my motivating use case, actually :P )

@kaos
Copy link
Member Author

kaos commented Dec 27, 2021

Another thing to consider is "plugin" fields, like how skip_flake8 is only registered ...

Oh, good point. Love it, will see what can be done here :)

kaos added 3 commits December 27, 2021 21:20
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]
@kaos
Copy link
Member Author

kaos commented Dec 27, 2021

@Eric-Arellano ok, we didn't track the providers for rules, so had to add that in too... but now we get this nice output:

$ ./pants help python_distribution
22:24:04.09 [INFO] Initializing scheduler...
22:24:04.58 [INFO] Scheduler initialized.

`python_distribution` target
----------------------------

A publishable Python setuptools distribution (e.g. an sdist or wheel).

See https://www.pantsbuild.org/v2.9/docs/python-distributions.


Provider: pants.backend.python
Valid fields:

[...]

repositories
    type: Iterable[str] | None
    default: None
    plugin: pants.backend.experimental.python
    List of URL addresses or Twine repository aliases where to publish the Python package.
    
    Twine is used for publishing Python packages, so the address to any kind of repository that Twine supports may be used here.
    
    Aliases are prefixed with `@` to refer to a config section in your Twine configuration, such as a `.pypirc` file. Use `@pypi` to upload to the public PyPi repository, which is the default when using Twine directly.

sdist
    type: bool
    default: True
    Whether to build an sdist for the distribution.

sdist_config_settings
    type: Dict[str, Iterable[str]] | None
    default: None
    PEP-517 config settings to pass to the build backend when building an sdist.

skip_twine
    type: bool
    default: False
    plugin: pants.backend.experimental.python
    If true, don't publish this target's packages using Twine.

@stuhood
Copy link
Member

stuhood commented Dec 27, 2021

Haven't looked at the details, but this is really awesome both for the CLI, and for the docsite. Thanks @kaos!

kaos added 2 commits December 28, 2021 10:25
[ci skip-rust]

[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@kaos
Copy link
Member Author

kaos commented Dec 28, 2021

Tweaked the wording slightly:

$ ./pants help python_distribution

`python_distribution` target
----------------------------

A publishable Python setuptools distribution (e.g. an sdist or wheel).

See https://www.pantsbuild.org/v2.9/docs/python-distributions.


Activated by pants.backend.python
Valid fields:

dependencies
[...]
skip_twine
    from: pants.backend.experimental.python
    type: bool
    default: False

    If true, don't publish this target's packages using Twine.

[...]

Also added a separating line between the field headers and the description, to make it more readable, imo.

@kaos kaos requested a review from Eric-Arellano January 5, 2022 13:48
@kaos kaos mentioned this pull request Jan 5, 2022
Copy link
Contributor

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

My favorite change of 2022 thus far 🎉😅

print(self.maybe_cyan(f"{indent}type: {field.type_hint}"))
print(self.maybe_cyan(f"{indent}{required_or_default}"))
if field.description:
formatted_desc = "\n".join(
hard_wrap(field.description, indent=len(indent), width=self._width)
)
print(formatted_desc)
print("\n" + formatted_desc)
Copy link
Contributor

Choose a reason for hiding this comment

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

Good change.

@kaos kaos merged commit 2d12f66 into pantsbuild:main Jan 5, 2022
@kaos kaos deleted the help_info_backend_source branch January 5, 2022 17:36
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.

3 participants