Skip to content

[doc] Show never-run testcode blocks as plain code blocks - #66974

Merged
dstrodtman merged 3 commits into
masterfrom
doc-1822-never-run-testcode
Oct 20, 2026
Merged

dstrodtman merged 3 commits into
masterfrom
doc-1822-never-run-testcode

Conversation

@dstrodtman

@dstrodtman dstrodtman commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

A testcode block reads as code that CI runs. On doc pages, 217 of them never run. Most carry :skipif: True, which Ray's pytest-sphinx fork drops before it builds an example, so the block never even shows up as skipped. The rest sit on pages that no doctest target collects. Most of these date from the semgrep code-block-python rule that required testcode, which #65903 removed.

Changes

  • 45 doc pages: each never-run testcode block becomes a plain fenced python block, or .. code-block:: python in rST. Its paired testoutput becomes a text block. pytest-sphinx attaches a testoutput to the nearest preceding testcode, so leaving one behind would pin its output onto an earlier block that does run.
  • The 8 never-run blocks marked :hide: are deleted. Readers never saw them and CI never ran them.
  • The hasattr self-check asserts in the collective backend example are dropped. The asserts in testing-tips.md and the local-mode unit test stay, because they're what those examples teach.
  • writing-code-snippets.md no longer teaches :skipif: True. Code CI can't run goes in a plain code block, with a text block for sample output.
  • doc/test_prose_doctest_targets.py and doc/BUILD.bazel: core/handling-dependencies.md and train/horovod.md no longer hold a runnable example, so they leave UNTESTED, and the BUILD comments that explained their missing targets are trimmed.

Docstring testcode under python/ray/ is out of scope. It's moving to >>> examples in separate PRs, because code-block doesn't suit docstrings.

Duplicate check

No open PR covers this. Searches for skipif, testcode, and writing-code-snippets return only my own docstring-convergence PRs (#66745, #66746, #66812) and #66809, which this PR builds on and which has merged.

Testing

  • For every changed page, I extracted examples with the pinned pytest-sphinx fork (ray-project/pytest-sphinx@c1ab2b33, docstring2examples, pytest==7.4.4) before and after the change. On the 36 pages a doctest target collects, the examples are identical: same source, expected output, and options. The 9 pages whose examples changed are exactly the pages no target collects, so no test result changes.
  • python doc/test_prose_doctest_targets.py passes: "45 listed pages; every runnable page is accounted for." Without the two UNTESTED removals, it fails on both as stale.
  • pre-commit run on all changed files passes.
  • No :skipif: remains under doc/ except the guide's instruction not to use it.
  • Not run: a Sphinx build. The edits are directive-to-fence swaps, and the Read the Docs preview is the check.

AI assistance (Claude Code) was used to write this change.

🤖 Generated with Claude Code

@dstrodtman
dstrodtman requested review from a team as code owners October 13, 2026 20:50

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the documentation by replacing testcode blocks containing :skipif: True with plain python code blocks, and testoutput blocks with plain text blocks, following updated guidelines in writing-code-snippets.md. Additionally, build and test configurations are updated to run tests on previously excluded files. The review feedback suggests keeping the assert hasattr(...) interface checks in ray-collective-custom-backend.md to preserve their educational value for readers, since moving them to a plain code block avoids any CI execution overhead.

@ray-gardener ray-gardener Bot added docs An issue or change related to documentation core Issues that should be addressed in Ray Core labels Oct 14, 2026
dstrodtman added a commit that referenced this pull request Oct 14, 2026
## Why are these changes needed?

About 75 links in `doc/source/` point back to the Ray docs through
absolute `docs.ray.io` URLs instead of in-tree references. They pin
readers to `/en/latest` or `/en/master` regardless of which version
they're reading, and a few pin to `releases-2.7.0` and `releases-2.48.0`
and show years-old content. They also bypass Sphinx's cross-reference
checking, so a moved page breaks silently. Many already resolve only
through redirects after the `ray-core/` to `core/` move.

This PR replaces them with in-tree references:

- Relative `.md`/`.ipynb` paths, with heading anchors where the original
linked a section.
- `{ref}` labels where the original anchor no longer exists as a
heading. Examples are `system-metrics`, `application-level-metrics`,
`serve-cli`, and `serve-in-production-config-file`.
- `{doc}` for rST targets, per `doc/AGENTS.md`.
- `{func}` and `{class}` for API reference pages: `ray.remote`,
`ray.serve.start`, and `ServeApplicationSchema`.

Link text is unchanged except where a role required it. The edits span
KubeRay, RLlib, Core, Serve, Data, Train, observability, and the
contributor guide, plus eight example notebooks, where only markdown
cells changed.

Out of scope, on purpose:

- URLs in code blocks, code cells, and config files. Those are correct
as absolute URLs.
- `doc/source/templates/`. It's excluded from the build and slated for
removal.
- The `serve/tutorials/video-analysis/` and
`train/examples/jax/intro-to-jax-trainer/` README pairs. The right link
form depends on whether they become Anyscale templates, which is still
being decided.
- `_includes/_latest_contribution_doc.rst`, which deliberately points
versioned builds at `/master`.

## Related issue number

None. This is the follow-on to #66742, which fixes the links into the
new `/kuberay/` paths. This PR doesn't touch any link #66742 changes, so
the two merge independently. I checked open PRs touching the same files:
#66664, #66850, and #66974 edit different lines.

## Checks

- [x] I've signed off every commit (DCO).
- [x] Built the docs locally with the RtD-faithful target: `make -C doc
rtd-build`, which runs `sphinx-build -a -E -W --keep-going` with Python
3.11 and the docs lock. Result: `build succeeded.`, exit 0, and no
Sphinx warnings under `-W`. The only `WARNING` lines in the log are
RLlib's own logger output from `compression.py` and `distributions.py`.
- [x] Spot-checked rendered hrefs in `_build/html`. For example,
`kuberay/user-guides/tls.html` now links
`../../core/configure.html#tls-authentication`, and
`serve/advanced-guides/grpc-guide.html` links
`../api/cli.html#serve-cli` and the `ray.serve.start` reference page.
- Prose and notebook markdown only, so no tests apply.

AI assistance was used to find the links, map each one to its current
source, and apply the edits. This PR stays in draft until the submitter
has reviewed every changed line.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

@abrarsheikh abrarsheikh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice .

@dstrodtman
dstrodtman added this pull request to stack #67009 October 14, 2026 16:11
Base automatically changed from doc-1708-per-file-doctests to master October 15, 2026 18:32
@dstrodtman
dstrodtman force-pushed the doc-1822-never-run-testcode branch from d0b8e09 to e71e04b Compare October 15, 2026 18:41
@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Oct 15, 2026
@dstrodtman
dstrodtman force-pushed the doc-1822-never-run-testcode branch from e71e04b to b84735f Compare October 15, 2026 19:30
@dstrodtman dstrodtman added the docs-go RtD-only checks for docs-only changes. Doesn't run full library doc-test suites. label Oct 15, 2026
dstrodtman and others added 3 commits October 20, 2026 09:26
217 testcode blocks on 45 doc pages never ran in CI: either they carried
`:skipif: True`, which the pytest-sphinx fork drops before collection, or
they sat on a page no doctest target collects. They read as tested code
without being tested.

Convert each to a plain fenced block (`code-block` in rST), and convert
its paired testoutput to a `text` block so the output doesn't attach to an
earlier testcode. Delete the 8 hidden blocks, which readers never saw and
CI never ran, and drop the self-check asserts in the collective backend
example. Remove two comments about a mocked testoutput that no longer
exists.

handling-dependencies.md and horovod.md no longer hold a runnable example,
so remove them from UNTESTED and from the BUILD comments that explained
why they had no target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
A testcode block should mean CI runs it. Tell contributors to show code
CI can't run as a plain code block, with a `text` block for sample
output, and show the guide's own rendered example the same way, since no
doctest target collects this page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
Any doc/BUILD.bazel change routes to every library's docs example step
and the llm suites, so the two comment-only edits here started all of
them on a prose-only PR. The stacked doctest-gaps PR already edits
doc/BUILD.bazel and carries these edits instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman force-pushed the doc-1822-never-run-testcode branch from cb00438 to 0f288c5 Compare October 20, 2026 13:26
@dstrodtman
dstrodtman merged commit cff1235 into master Oct 20, 2026
6 checks passed
@dstrodtman
dstrodtman deleted the doc-1822-never-run-testcode branch October 20, 2026 15:28
dstrodtman added a commit that referenced this pull request Oct 20, 2026
## Why are these changes needed?

Builds on #66974.

This PR changes only files under `doc/`, so it needs no
`@ray-project/ray-ci` review. #66809 routes all prose under
`doc/source/` to the `docs-example-test` opt-in, so giving a page a
target here doesn't touch `.buildkite/`. The per-page routing this PR
used to add, 27 page paths in `test.rules.txt`, is the kind of edit
#66809 removes.

#66809 gives Core, RLlib, Serve, and Train pages one doctest target
each, listing only pages with something to run. Two doc doctest targets
still glob directories, so they report passes with nothing behind them:

- The catch-all `//doc:doctest` globs 214 pages that no library owns. 8
of them have a runnable example.
- Ray Data's `doctest_each` globs `source/data/`. 12 of its 31 per-page
targets, such as `user-guide`, `benchmark`, and `api/api`, run nothing.

### Changes

- `doc/BUILD.bazel`: the catch-all becomes `doctest_each()` over its 8
runnable pages, still tagged `team:none` with the Ray Data pytest
plugin, so the postmerge `doc: doctest` step selects them unchanged. Its
17 exclude lines go away, including the three for pages that #66974 left
with nothing to run. Data lists its 19 runnable CPU pages. The GPU
targets are unchanged.
- `doc/test_prose_doctest_targets.py`: the lint now covers every page
under `doc/source`, not five library directories. A runnable page
anywhere needs a target, or an `UNTESTED` entry with a reason. Two pages
join `UNTESTED`: the contributor pages whose `>>>` samples teach doctest
syntax. Both were excluded from the catch-all before. The lint also
ignores comments when it reads targets from `doc/BUILD.bazel`.
- `doc/source/ray-contribute/ci.md`: the `docs-example-test` label now
runs any changed page with a runnable example. The "feeds only a shared
doctest target" case is gone, because no multi-page CPU prose target
remains.

The comment above the postmerge `doc: doctest` step in
`.buildkite/others.rayci.yml` still calls `//doc:doctest` a single
catch-all target. It's left for a later CI change so this PR stays
docs-only.

### Target renames

`//doc:doctest` becomes 8 per-page targets such as
`//doc:source/ray-references/glossary`. The catch-all step runs with the
test DB disabled, so no flaky-test history is lost. Data's 12 empty
targets disappear.

## Duplicate check

No open PR covers this. The adjacent work is #66809, which split the
other libraries' targets, and #66974, which this PR builds on. #66809
changes only the Core, RLlib, Serve, Train, and Tune targets.

## Testing

- `./ci/lint/lint.sh doc_prose_doctest_targets` passes: "74 listed
pages; every runnable page is accounted for." On scratch copies of the
tree, each new failure mode fires: a runnable unlisted page outside the
library directories, a catch-all page dropped from BUILD, and an empty
Data page listed.
- `rayci test-rules` (rayci v0.48.0, built from source) passes on this
branch. This PR doesn't change the rules files.
- `bazel query 'attr(tags, "doctest", tests(//doc:all))'` lists 72
targets. The `team:none` query lists the 8 catch-all pages.
- `bazel run //ci/ray_ci/doc:cmd_doc_example_targets --
doc/source/ray-references/glossary.md doc/source/data/benchmark.md
doc/source/data/loading-data.md` selects
`//doc:source/ray-references/glossary` under team `none` and
`//doc:source/data/loading-data` under `data`, and reports "No test
names this file" for `benchmark.md`.
- `buildifier` and `pre-commit run` on all changed files pass.
- Not run locally: the doctests themselves. Each page runs the same
files with the same plugin as before, now one page per target. The
postmerge build and a `docs-example-test` labeled run are the checks.

AI assistance (Claude Code) was used to write this change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
dstrodtman added a commit that referenced this pull request Oct 21, 2026
## Why are these changes needed?

A rolling batch of small, independent docs fixes. Ray's `AGENTS.md`
permits mechanical cleanups when they're bundled rather than opened one
per PR, so they collect here. Each fix is its own commit, so a reviewer
can drop any one without disturbing the rest. This stays a draft while
it collects fixes.

### Fixes

- **Show the never-run TorchTPU example as a plain code block**
(`train/user-guides/using-accelerators.md`). #66991 added the TorchTPU
example as a `testcode` block with `:skipif: True`. Since #66974,
`writing-code-snippets.md` says not to do that, because the block never
runs but reads as tested code. It's now a plain `python` block, like the
JAX TPU example above it. It was the last `:skipif: True` block under
`doc/source/`.
- **Fix the broken PyTorch Neuron setup link**
(`serve/tutorials/aws-neuron-core-inference-stable-diffusion.md`). AWS
moved the Neuron setup page, so `frameworks/torch/torch-setup.html`
returns 404 and the scheduled docs link check flags it. The link now
points at `setup/torch-neuronx.html`, which the sibling
`aws-neuron-core-inference.md` tutorial already uses.
- **Link the GIL to the Python glossary** (`core/actors/async-api.md`).
The Python wiki dropped its `/moin/` paths, so
`wiki.python.org/moin/GlobalInterpreterLock` returns 404. The link now
goes to the glossary entry in the official Python docs,
`docs.python.org/3/glossary.html#term-global-interpreter-lock`.

## Related issue number

None.

## Duplicate check

Not a duplicate. `gh pr list --repo ray-project/ray --state open
--search "using-accelerators skipif"` returns nothing, and #67194, which
restyled the same TPU pages, left this block as it was.

## Testing

- Both new link targets return 200, and the glossary page contains the
`term-global-interpreter-lock` anchor. The two old URLs return 404.
- `python doc/test_prose_doctest_targets.py` passes: "74 listed pages;
every runnable page is accounted for." The page still has other runnable
blocks, so it stays in `doctest[train-gpu]`.
- `git grep -n skipif -- doc/source` now finds only the guide's
instruction not to use it.
- Extracting the page's examples is unaffected for runnable blocks:
pytest-sphinx drops a `:skipif: True` block before it builds an example,
so this block was never collected.
- `pre-commit` passes on the changed file.

AI assistance (Claude Code) was used to find and make these fixes. I
reviewed every changed line.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
dstrodtman added a commit that referenced this pull request Oct 30, 2026
## Description

This PR retires the notebook authoring templates and the contributor
guidance that points new examples at notebooks.

`doc/source/_templates/template.ipynb` is a Jupyter starter for new doc
examples. It isn't a page, because `templates_path` keeps `_templates/`
out of the source files Sphinx reads. Nothing includes it, and no bazel
target runs it. Its MyST sibling, `template.md`, is out of date. It
imports `ray.rllib.agents.ppo`, demos `{eval-rst}` and `{margin}`, and
teaches `{code-cell}` notebooks that no build or test target executes.
The "Creating a notebook example" section of the contributor guide links
both templates, tells contributors to download the page as an `.ipynb`,
and recommends converting their draft to `.ipynb` when they finish.

This PR deletes the Jupyter template and turns `template.md` into a
template for an end-to-end guide written as an ordinary MyST page. The
contributor guidance now says that a guide like this is a Markdown page
its author ran, not a tested asset, and sends examples that need testing
to the template-collections flow. The template and guidance changes come
from #67428, which merged into this branch.

### What this PR changes

- Deletes `doc/source/_templates/template.ipynb`.
- `doc/source/_templates/template.md`: rewrites it as an end-to-end
guide skeleton. It uses only MyST, sphinx-design (`tab-set`,
`dropdown`), colon-fence admonitions, and `{ref}` and `{py:func}` roles,
with no myst-nb notebook syntax. A maintainer-only HTML comment under
the title records that Ray CI doesn't test the guide and which Ray
version its author last ran it with. The example code is a minimal Ray
Core task. Sphinx still excludes the file through `_templates/`.
- `doc/source/ray-contribute/docs.md`:
- Replaces "Creating a notebook example" (label
`creating-notebook-example`) with "Writing an end-to-end guide"
(`writing-e2e-guide`). The new section points to the template and says
Ray CI doesn't run the guide's code, so the author runs every step and
records the Ray version. It sends tested examples to the
template-collections flow and says not to add notebooks or notebook
front matter. To convert an existing notebook, it gives `jupyter
nbconvert --to markdown`.
- Removes what the old section taught: the Jupyter template link,
downloading the page as an `.ipynb`, the Tune Hyperopt notebook as a
model, the kernel specification front matter, `code-cell` examples, cell
tags, reference labels, removed-cell testing, and the `jupytext`
conversions. It also drops the claim that CI tests every notebook placed
in the Tune `examples` folder.
- Updates the format overview and the "two types of documents" list so
they no longer present notebooks as the format for new examples.
- "Adding code to an `.rST` or `.md` file": drops the claim that every
snippet is tested and the `.. code-cell:: python` recommendation. Tested
code uses `testcode` or a `literalinclude` script, and code that CI
can't run goes in a plain fenced block.
  - Links "How to write code snippets" by its `.md` file name.
- "Writing an end-to-end guide": offers an `examples.yml` gallery only
for Ray Data, Ray Serve, and Ray Train, the only libraries that have
one. `conf.py` marks gallery-linked pages as orphans, so the page needs
no `orphan` front matter. It also says what `nbconvert` does with
outputs and images.
- Replaces "Every Python file in the `doc_code` directory is
automatically tested." Some files and directories have no target in
`doc/BUILD.bazel`, so it now tells contributors to check that a target
covers their script.
- `doc/source/ray-contribute/writing-style.md`, "Code blocks": replaces
"Every runnable snippet in the docs is tested." It now names the two
tested forms, a `testcode` block on a page with a doctest target in
`doc/BUILD.bazel` and a `doc_code/` script included with
`literalinclude`. It limits both to code that runs as written and that
CI should test, and says CI doesn't run a plain fenced block. Since
#67432, no documentation page runs a `>>>` example, and #67429 updates
`writing-code-snippets.md` to match.
- `doc/source/ray-contribute/publishing-examples-legacy.md`: takes over
the cell-tag guidance (`hide-*`, `remove-*`, and overriding realistic
values in a removed cell), rewritten for `.ipynb` cell metadata. It
applies only to the remaining in-tree notebooks.
- `doc/source/ray-contribute/publishing-examples.md`: repoints its
cross-reference to `writing-e2e-guide`. No reference to the old label
remains.
- `.buildkite/test.rules.txt`: deletes the `doc/source/_templates/` skip
rule. It existed to keep `template.ipynb` off the `doc/*.ipynb`
catch-all. Every remaining file under `_templates/` (`.html`, `.rst`,
`.md`, `.gitkeep`) gets the same tags without it: `.md` and `.rst` files
hit the leading prose skip first, and the rest fall through to the broad
`doc/` skip.
- `.buildkite/test.rules.test.txt`: replaces the `template.ipynb` case
with `doc/source/_templates/layout.html:`.

### Merge-order note for #67012

#67012 adds `doc/asset_allowlists/notebooks.txt`, which lists
`doc/source/_templates/template.ipynb`, and its check fails on an entry
whose file is gone. Neither PR depends on the other, and they merge
without textual conflicts. Whichever merges second deletes that line. If
this PR merges first, `python doc/test_doc_assets.py --update` on #67012
removes it. With this branch, current master, and #67012 merged
together, the check fails only on that line and passes once it's
deleted.

## Related issues

Includes #67428, which merged into this branch. #67429 is stacked on
this branch, and #67639 is stacked on #67429. #67639 limits the legacy
notebook page to maintaining the two remaining notebook examples.
Follows #67008, which rewrote the same comment blocks in
`test.rules.txt` and `test.rules.test.txt`, and #66974, which moved
never-run `testcode` blocks to plain code blocks.

## Additional information

### Duplicate check

I searched open PRs for `template.ipynb`, `template.md`, `_templates`,
`notebook template`, `end-to-end guide`, `creating-notebook-example`,
`ray-contribute/docs.md`, `writing-style.md`, and `publishing-examples`,
then compared the files each docs PR in the results changes with this
PR's. No open PR removes either template or rewrites these sections. The
open PRs that touch the same files edit other hunks:

- #66462 and #67012 edit `test.rules.txt` and `test.rules.test.txt`.
Each merges with this branch without conflicts. #67204, which edited
`docs.md` and `writing-style.md`, has merged, and this branch is rebased
on it.
- #67018 edits a section of `writing-style.md` about 170 lines below
this PR's hunk.
- #67429 and #67639 are stacked on this branch.

### Testing

On this branch's head, rebased on master on 2026-10-30:

- `rayci test-rules`, using v0.51.0, the version `.rayciversion` pins,
built from `ray-project/rayci`: 197/197 cases pass, and the check also
passes with the branch merged with current master. Changing the new
`layout.html` case to expect `doc` makes it fail, so the case is live.
- Routing equivalence: I added every file under `doc/source/_templates/`
as a case that expects no tags. `rayci test-rules` passes both with and
without the deleted rule. The only file whose routing the rule changes
is `template.ipynb`, which routes to `doc_example` without it.
- `pre-commit run --files` on the changed files passes, including the
check that links to files on master resolve.
- `vale` on the changed pages: `docs.md` goes from 98 alerts to 71, and
the other pages stay level or drop. The only new alerts are spelling
flags on "toctree" and "doctest", terms these guides already use, and a
passive-voice flag on an unchanged sentence in `docs.md`.
- `jupyter nbconvert your-example.ipynb --to markdown`, with nbconvert
7.17.2 on a copy of a Tune notebook, writes a Markdown file with
`python` code fences and no Jupyter front matter.
- The Read the Docs preview renders "Writing an end-to-end guide", the
`writing-e2e-guide` references in `docs.md` and `publishing-examples.md`
resolve to it, and the legacy page renders "Hide and remove cells".

From #67428:

- The template's example code, run with `ray[default]` 2.59.0 on Python
3.11, prints `[0, 1, 4, 9]`.
- A copy of the template with its placeholders filled in builds without
warnings using Sphinx 8.2.3, myst-parser 5.1.0, sphinx-design, and the
`myst_enable_extensions` from `conf.py`. The tab set, dropdown, and tip
render.

This PR was prepared with AI assistance (Claude Code), including the
commits from #67428. Each author reviewed every line they changed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ronny Roland <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Douglas Strodtman <[email protected]>
dstrodtman added a commit that referenced this pull request Oct 30, 2026
## Description

Stacked on #67426. #67639 is stacked on this PR.

`writing-code-snippets.md` presents *doctest-style* (`>>>`) examples as
an equal choice for docstrings and documentation pages. In practice,
documentation pages don't use them. When this PR opened, 7 Markdown or
rST pages under `doc/source/` had a `>>>` prompt, and only two of them
ran it on purpose. #67432 has since converted those page examples to
`testcode` and plain code blocks. On `master`, only
`writing-code-snippets.md` and `getting-involved.md` have `>>>` prompts,
and both teach the docstring format.

This PR makes the guidance match: `>>>` doctest examples belong in
docstrings, and documentation pages use `testcode` or `literalinclude`.

### What this PR changes

- `doc/source/ray-contribute/writing-code-snippets.md`:
- Front matter description and "Types of examples": *doctest-style* is
for docstrings, and the other two types are for documentation pages.
- The *doctest-style* example now uses the docstring `Example:` form
instead of `.. doctest::`. The tip about dropping `.. doctest::` in
docstrings becomes a note not to use *doctest-style* on documentation
pages.
- "Which type of example should you write?": where the example lives
decides the style. The *doctest-style* and skip examples use the
docstring form, and "When to use *code-output-style*" covers page
examples that show output.
  - Leaves the GPU section alone, because #67204 rewrote it.
- `doc/source/ray-contribute/writing-style.md`, "Code blocks": adds
"Reserve `>>>` doctest-style examples for docstrings."

This doesn't change `doc/BUILD.bazel`,
`doc/test_prose_doctest_targets.py`, or any page with `>>>` examples.

## Related issues

Stacked on #67426. Builds on #66974, which moved never-run `testcode`
blocks to plain code blocks.

## Additional information

### Duplicate check

I searched open PRs for `writing-code-snippets`, `doctest`, and
`testcode`. #67204 also edits `writing-code-snippets.md` and
`writing-style.md`, in other hunks. `git merge-tree` against it reports
no conflicts. No open PR changes when to use *doctest-style*.

### Testing

- The census: `git grep -c '^\s*>>> '` over `doc/source/*.md` and
`*.rst` on `upstream/master`, then each page's enclosing blocks and its
listing in `doc/BUILD.bazel` and `UNTESTED`.
- `python doc/test_prose_doctest_targets.py` passes: "73 listed pages;
every runnable page is accounted for."
- `pre-commit run --files` on the changed files passes.
- `vale` on `writing-code-snippets.md`: no new alerts except spelling
flags on *literalinclude*, which the page already uses throughout.
- The Read the Docs preview covers rendering.

This PR was prepared with AI assistance (Claude Code). I reviewed every
changed line.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core docs An issue or change related to documentation docs-go RtD-only checks for docs-only changes. Doesn't run full library doc-test suites. go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants