-
Notifications
You must be signed in to change notification settings - Fork 45
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
Documentation Inheritance #27
Comments
This is an extension of bazelbuild/skydoc#182 and a duplicate of bazelbuild/skydoc#115 (though contains more detail than the original FR issue) |
cc @ittaiz In your example, what happens with |
My proposal is that it appends the additional docstring to that of the inherited rule. In other words, bin_output for the macro would have docstring: That said, I can see that some users might want to override the documentation of the inherited rule, so perhaps the macro's account of bin_output should also have a |
Your example doesn't show it, but you could have extra args too.
Also, |
Sure. Lets address these by using a metatag per arg as well. def my_rule(name, otherarg, **kwargs):
"""@inherit(_my_rule)
Args:
bin_output: @argdoc(_my_rule.bin_output). `name` + '.exe' by default.
otherarg: Some new argument.
"""
_my_rule(name = name,
bin_output = name + ".exe",
**kwargs) When one specifies |
+1, sounds like a good suggestion. |
Slightly aside, but how are defaults handled for rules vs. macros? The example above uses the docstring on the macro to record the default value, but since defaults are also possible in macro definitions and rule definitions, wouldn't stardoc already pick those up? i.e. - would it end up generating something else to document the default which would conflict the the docstring the macro is adding? So taking this: def _rule_impl(ctx):
...
_my_rule = rule(
implementation = _my_rule_impl,
doc = "My rule is the best rule",
attrs = {
"foo" : attr.string(
default = "default value",
doc = "Lorem ipsum dolor sit amet",
)
}
)
def my_rule(name, foo="different_default", **kwargs):
"""@inherit(_my_rule)
Args:
foo: @argdoc(_my_rule.foo). more text here.
"""
_my_rule(name = name,
**kwargs) How exactly would |
I assume you mean, for definition of def my_rule(name, foo="different_default", **kwargs):
"""@inherit(_my_rule)
Args:
foo: @argdoc(_my_rule.foo). more text here.
"""
_my_rule(name = name,
foo = foo,
**kwargs) (note the I would hope the implementation for this feature would inherit the documentation via |
So that works for when the macro has a default, but going back to your example: def my_rule(name, **kwargs):
"""@inherit(_my_rule)
Args:
foo: @argdoc(_my_rule.foo). `name` + ' something' by default.
"""
foo = kwargs.pop('foo', name + ' something')
_my_rule(name = name,
foo = foo,
**kwargs) Now my docstring has to document the default and the rule will also provide a |
For what it's worth, in your above example, it wouldn't be appropriate to have However, we'd need to address the following example: def my_rule(name, **kwargs):
"""@inherit(_my_rule)"""
_my_rule(name = name,
foo = "something",
**kwargs) Indeed, rule documentation already includes a documented "default value" if available, so we would need to take that into account when allowing for inheritance. We wouldn't want the above example to have In other words, one should be able to Full disclosure, this is not something I likely have cycles for in Q4. Happy to accept contributions, though we'll likely need to evaluate a design before we delve right into implementation (we'd need to make sure these concerns are addressed!) |
Hey! Any updates on this? This feature would be awesome!!! 😄 |
Another friendly ping 😅 Any updates here? 🙏 |
Hi @UebelAndre, see #89 and in particular Prioritization. We won't be working on new features in the immediate future. |
Another upvote for this, with another motivating use case.
This is an ugly ordering, and only gets worse if I have more rules defined. What I would like is
I can work around this by generating each rule and macro separately, and then weaving them together, but yech. |
FWIW I hacked up something like this in rules_pkg earlier this year. So this string ends up like this in the final form. |
Instead of macros inheriting rule docs, a better solution might be a new way of declaring macros which uses rule-like attribute lists; the attribute list can then be shared (with whatever modifications one might want to apply) between the underlying rule and the new-style macro wrapper - which would propagate docs for free and would not have the risk of docs going stale (unlike inheritance annotations). CC @brandjon and @comius who are working on at least 2 different propasals in this area. |
As explained in bazelbuild/bazel#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:
There are several issues here:
my_rule
macro and the_my_rule
rule_my_rule
I propose a macro metatag (for Stardoc to recognize) which effectively notes inheritance of documentation. So instead:
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 bazelbuild/buildtools#649)
The text was updated successfully, but these errors were encountered: