-
Notifications
You must be signed in to change notification settings - Fork 177
Add recommendations for documenting Starlark APIs #320
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
Open
tetromino
wants to merge
5
commits into
bazelbuild:master
Choose a base branch
from
tetromino:conventions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+83
−2
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # Starlark Language Conventions | ||
|
|
||
| This document describes non-normative but generally recommended conventions for | ||
| Starlark. | ||
|
|
||
| ## API Documentation | ||
|
|
||
| ### Docstrings | ||
|
|
||
| API documentation for a Starlark module or function should be provided in a | ||
| *docstring* - a string literal which is the first statement of the module or of | ||
| the function's body. | ||
|
|
||
| By convention, this string should consist of an optional newline, followed by | ||
| a 1-line, 1-sentence summary, optionally followed by a blank line and blank-line | ||
| delimited paragraphs of additional documentation text. | ||
|
|
||
| For example: | ||
|
|
||
| ```python | ||
| """A collection of useful utilities.""" | ||
|
|
||
| def is_valid(config): | ||
| """ | ||
| Verifies if `config` is a valid configuration. | ||
|
|
||
| Usage example: | ||
|
|
||
| is_valid({"example": {"cpu": "arm"}}) # returns True | ||
| """ | ||
| ... | ||
| ``` | ||
|
|
||
| No particular markup format for the text is prescribed; we observe that Markdown | ||
| and HTML are commonly used in practice. Of course, projects and organizations | ||
| can specify additional guidelines for their documentation formatting. | ||
|
|
||
| Documentation processing tools - especially if interpreting docstrings as | ||
| Markdown-formatted - should take care to dedent common leading whitespace from a | ||
| multiline docstring's lines (note that the first line could have no leading | ||
| whitespace). | ||
|
|
||
| ### Doc comments | ||
|
|
||
| API documentation for a global variable may be provided in [Sphinx | ||
| autodoc-style](https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#doc-comments-and-docstrings) | ||
| *doc comments*, which start with `#:` optionally followed by one space. | ||
|
|
||
| An uninterrupted sequence of one or more lines which contain *only* doc comments | ||
| (optionally preceded by whitespace before the `#:`) forms a *doc comment block*. | ||
| Such a doc comment block attaches to the symbol(s) on the left hand side of the | ||
| assignment statement that starts on the immediately following line: | ||
|
|
||
| ```python | ||
| #: List of allowed configuration names | ||
| #: in priority order | ||
| ALLOWED_CONFIGS = ["foo", "bar"] | ||
|
brandjon marked this conversation as resolved.
|
||
|
|
||
| #: Default foo map | ||
| FOO_MAP, _ = generate_foo_and_bar_maps() | ||
| ``` | ||
|
|
||
| Alternatively, a one-line trailing doc comment may be given inline after the end | ||
| of the right-hand side of an assignment statement: | ||
|
|
||
| ```python | ||
| DEFAULT_TAGS = { | ||
| "foo": [], | ||
| "bar": ["local", "manual"], | ||
| } #: Default list of tags for each configuration | ||
| ``` | ||
|
|
||
| Documentation processing tools may treat multiple doc comments attached to the | ||
| same variable as an error (for example, if a variable has both a preceding doc | ||
| comment block and a trailing in-line doc comment). | ||
|
|
||
| Doc comments attach to variables, not to values. For example, if a global | ||
| variable whose value happens to be `True` has a doc comment, documentation | ||
| processing tools shouldn't attach the doc comment's text to unrelated | ||
| occurrences of `True` in other parts of the code. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.