Skip to content

Commit 21d36f3

Browse files
authored
agents: refine Starlark data serialization, docstring, and WORKSPACE rules (bazel-contrib#4364)
Capture review feedback from bazel-contrib#4360 in the workspace agent rules so future Starlark and WORKSPACE implementations follow the same patterns: - Direct repository rules to serialize JSON-compatible data constants in generated `.bzl` files with `json.encode_indent()` instead of custom `render.*` helpers. - Keep `.bzl` API docstrings brief and place multi-scenario examples and setup guides in narrative `docs/` pages linked via `{ref}` or `{obj}`. - Require `WORKSPACE` macros to match Bzlmod extension defaults, tag schemas, and single-hub multi-version structure, splitting manifest downloads into a manifest repo rule and a bound registration macro.
1 parent 44eb677 commit 21d36f3

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎.agents/rules/docs.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ globs: "docs/**,RELEASING.md"
1111
* Use hyphens (`-`) in file names instead of underscores (`_`).
1212
* Document user-visible behavior, not internal workarounds or implementation
1313
details.
14+
* **API Docstrings vs. Narrative Docs**: Keep `.bzl` docstrings brief (purpose
15+
and arguments). Put setup guides and multi-scenario examples in `docs/`, and
16+
link to them with `{ref}` or `{obj}` instead of repeating rules.
1417
* **How-to Guides (`docs/howto/`)**:
1518
* Prefer adding sections to an existing topical guide (e.g.
1619
`docs/howto/build-a-wheel.md`) over creating a separate granular file.

‎.agents/rules/rules_python.md‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ description: rules_python-specific Bzlmod, PyPI, and rule usage invariants
2828
`//python/private/toolchain_types:BUILD.bazel`.
2929
* **`render` Helpers (`//python/private:text_util.bzl`)**: Use `render.*`
3030
(`render.string`, `render.toolchain`, `render.call`, `render.list`) instead of
31-
`repr()` when generating Starlark calls.
31+
`repr()` for Starlark calls; use `json.encode_indent()` for data constants.
3232
* **`@bazel_tools` `bzl_library` Deps**: Use `"//python/private:bazel_tools"` in
3333
`bzl_library` `deps` for files loading `@bazel_tools//...`.
34+
35+
## WORKSPACE & Bzlmod Parity
36+
* Match Bzlmod extension defaults, tag schemas (e.g., `configure` list of
37+
dicts), and single-hub multi-version structure in `WORKSPACE` macros. Share
38+
configuration and hub logic in common private `.bzl` helpers.
39+
* When `WORKSPACE` repos depend on downloaded manifests, split setup into a
40+
manifest repo rule (writes unfiltered `DIST_MANIFESTS` and a bound
41+
registration macro to `dist_manifest.bzl`) and a registration macro (filters
42+
platforms, instantiates tool repos, and registers the hub; also accepts
43+
explicit `urls` without a manifest).

‎.agents/rules/starlark.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ globs: "*.bzl,BUILD,BUILD.bazel,*.bazel"
7272
render `BUILD.bazel` in the rule implementation.
7373
* **Single-Value Templates**: For generated file templates with one interpolated
7474
value, use a top-level string and `.format()`.
75+
* **Data Constants in Generated `.bzl` Files**: Use `json.encode_indent()` to
76+
write JSON-compatible data (`dict`, `list`, `str`, `int` without `bool` or
77+
`None`) as `.bzl` constants instead of custom formatting helpers.
7578
* **Reuse `http_file`**: Use `http_file` from
7679
`@bazel_tools//tools/build_defs/repo:http.bzl` for single-file downloads. Omit
7780
`downloaded_file_path` unless required and reference `@<repo>//file`.
@@ -124,6 +127,9 @@ globs: "*.bzl,BUILD,BUILD.bazel,*.bazel"
124127
instead of passing them through `**kwargs`. Document `Args:` and `Returns:`.
125128
* **Docstring Formatting Invariants**: Use triple-quoted strings for multi-line
126129
docstrings without trailing backslashes (`\`) for line continuation.
130+
* **Concise API Docstrings**: Keep docstrings brief: state purpose and
131+
arguments, link to shared symbols (`{obj}`) or guides (`{ref}`) instead of
132+
repeating rules, and put extended examples in `docs/`.
127133
* **Workaround Comments**: Comment non-obvious workarounds with the intent, why
128134
the direct approach fails, and why the workaround works.
129135
* **No Bazel Copyright Headers**: Do not add Bazel copyright headers to new or

0 commit comments

Comments
 (0)