bazelbuild / bazelbuild/stardoc

Documentation Inheritance

Open
#27 16 comments 6 reactions 0 assignees View on GitHub
P3 type: feature request
Dominant language
Java
Stars
118
Forks
51
PR merge metrics
No merged PRs in 30d

Description

As explained in https://github.com/bazelbuild/bazel/issues/7977, there's a common use case for macros which serve as thin wrappers on rule invocations. In such cases, it's inconvenient and maintenance-heavy to manually mirror rule documentation as macro documentation:

```python
def _rule_impl(ctx):
bin_output = ctx.outputs.bin_output
...
return [OutputGroupInfo(bin = depset([bin_output])]

_my_rule = rule(
implementation = _my_rule_impl,
doc = "My rule is the best rule",
attrs = {
"bin_output" : attr.output(doc = "Binary output"),
"foo" : attr.string(doc = "Lorem ipsum dolor sit amet")
}
)

def my_rule(name, **kwargs):
"""My rule is the best rule.

Args:
name: The name of the test rule.
foo: Lorem ipsum dolor sit amet
bin_output: Binary output. `name` + '.exe' by default.
**kwargs: Other attributes to include
"""

_my_rule(name = name,
bin_output = name + ".exe",
**kwargs)
```

There are several issues here:

- Duplication between the root and argument documentation in the `my_rule` macro and the `_my_rule` rule
- The Args section of the macro does not appropriately match the rule. There is no "foo" parameter of the macro, but it might be part of kwargs.
- We need not document kwargs, as all kwargs should also be documented in `_my_rule`

I propose a macro metatag (for Stardoc to recognize) which effectively notes inheritance of documentation. So instead:

```python
def my_rule(name, **kwargs):
"""@inherit(_my_rule)

Args:
bin_output: `name` + '.exe' by default.
"""

_my_rule(name = name,
bin_output = name + ".exe",
**kwargs)
```

Note this new format will **also** need to be recognized by buildifier, so that buildifier does not emit warnings even if the Args section of the macro's docstring does not match the arguments of the macro. (Related to https://github.com/bazelbuild/buildtools/issues/649)

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the proposed inheritance behavior in this issue, along with the related Bazel issue 7977 and buildifier issue 649. Trace the Stardoc and buildifier entry points that parse macro docstrings; done means the inheritance format is defined, Stardoc can use it, and buildifier no longer warns for the documented macro pattern.

Written by the indexing model from the issue text.

Assessment

Domain
documentation, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.