Skip to content

[doc] Convert the remaining page doctests to testcode and plain code blocks - #67432

Merged
dstrodtman merged 4 commits into
masterfrom
djs-261026-convert-prose-doctests
Oct 29, 2026
Merged

dstrodtman merged 4 commits into
masterfrom
djs-261026-convert-prose-doctests

Conversation

@dstrodtman

Copy link
Copy Markdown
Contributor

Description

Converts the last >>> doctest examples on documentation pages, so >>> examples remain only in docstrings and on the two pages that teach the docstring format. #67429 changes the contributor guidance to match. This PR is independent of that stack and targets master.

Before this PR, seven pages under doc/source/ had >>> prompts. Two of them teach the docstring format and stay as they are: ray-contribute/writing-code-snippets.md and ray-contribute/getting-involved.md. This PR converts the other five:

Page Before After Test coverage
data/working-with-tensors.md Three {doctest} blocks {testcode} and {testoutput} blocks Unchanged. The dtype and shape checks still run. The two per-image shapes the doctest skipped are now a +MOCK sample.
ray-references/glossary.md One {doctest} block with +SKIP on every line {testcode} and {testoutput} Gained. The block used to run nothing and now runs. The expected output is unchanged, because Ray produces it exactly.
serve/advanced-guides/multi-app-container.md >>> prompts in a python fence, with every request skipped Plain python and text blocks None before or after. The requests need the containerized Serve apps running. The doctest only ran import requests and two string assignments.
core/tasks/nested-tasks.md REPL transcript in a bash block Plain python and text blocks None before or after. The page's doc_code/ script is tested.
serve/production-guide/fault-tolerance.md Interactive $ python / >>> transcripts Plain python blocks, with text blocks for output None before or after. These steps kill actors on a live cluster.

Test wiring

  • doc/BUILD.bazel:
    • Removes the Serve doctest_each call. Its only file was multi-app-container.md, which no longer has a runnable example, so the target would pass without testing anything.
    • Drops the comment explaining why nested-tasks.md isn't listed, since the page no longer has anything runnable to explain.
    • The glossary and tensors entries stay, because both pages still have runnable examples.
  • doc/test_prose_doctest_targets.py: removes nested-tasks.md and fault-tolerance.md from UNTESTED. Neither page has a runnable example now. The two docstring-teaching pages stay exempt.

No .buildkite/test.rules.txt change. All prose routes to doc_example whether or not a doctest target names the page, and the existing routing cases for these pages still hold.

This PR edits doc/BUILD.bazel, so premerge runs every library's docs example step. The glossary target is tagged team:none, which runs only post-merge or with docs-example-test, so this PR carries that label too.

Related issues

Companion to #67429, which reserves >>> doctest-style examples for docstrings in the contributor guide.

Additional information

Duplicate check

I searched open PRs for each converted page and for doctest in titles. #66705 edits fault-tolerance.md around line 53, far from these hunks. Draft #66851 appends a line to nested-tasks.md after these hunks. Neither converts these examples. The docstring conversion PRs (#67238, #66745, #67237) touch python/, not pages.

Testing

I reproduced the CI doctest runner locally: Ray 2.59.0, Python 3.11, pytest==7.4.4, ray-project/pytest-sphinx@c1ab2b33, the Ray Data doctest_pytest_plugin.py, and the macro's --doctest-modules --doctest-glob='*.md' -c NO_PYTEST_CONFIG arguments.

  • working-with-tensors.md: passes before (2 items: the doctest blocks and the testcode blocks) and after (1 item). A copy with a wrong expected shape fails with Expected (32, 28, 99) / Got (32, 28, 28), so the new assertions are live.
  • glossary.md: before, 1 skipped. After, 1 passed. A copy with a wrong expected value fails.
  • python doc/test_prose_doctest_targets.py: "73 listed pages; every runnable page is accounted for."
  • pre-commit run --files on the changed files passes, including buildifier and buildifier-lint.
  • vale on each changed page: no new alerts compared with master.
  • After this PR, git grep -l '^\s*>>> ' over doc/source/*.md and *.rst returns only the two pages that teach the docstring format.
  • 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

…blocks

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman requested review from a team as code owners October 26, 2026 16:40
@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Oct 26, 2026
@dstrodtman
dstrodtman requested a review from a team as a code owner October 26, 2026 16:40
@dstrodtman dstrodtman added the docs-example-test Opt into narrowly-scoped testing for docs example code. label Oct 26, 2026
@dstrodtman
dstrodtman requested review from a team as code owners October 26, 2026 16:40
@dstrodtman dstrodtman added go add ONLY when ready to merge, run all tests docs-example-test Opt into narrowly-scoped testing for docs example code. labels Oct 26, 2026

@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 updates various documentation files to improve testability by migrating from legacy doctest blocks to explicit testcode and testoutput blocks. This change enables better validation of code snippets in the documentation. I have reviewed the changes and agree with the suggestion to use json.dumps for pretty-printing JSON output to ensure the code execution results match the provided documentation examples.

@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 26, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7887cdc. Configure here.

Comment thread doc/source/ray-references/glossary.md Resolved
…utput is stable

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

@ronny-anyscale ronny-anyscale 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.

lgtm

@dstrodtman
dstrodtman merged commit 9deed3c into master Oct 29, 2026
6 checks passed
@dstrodtman
dstrodtman deleted the djs-261026-convert-prose-doctests branch October 29, 2026 20:40
dstrodtman added a commit that referenced this pull request Oct 30, 2026
#67593)

## Description

Brings the `rst-to-myst` agent skill in
`doc/.claude/skills/rst-to-myst/` up to date. The copy here was frozen
on 2026-09-18 while the skill kept evolving outside the repo during the
prose conversion. With the prose pages converted, this makes the in-repo
copy the only one. The skill isn't documentation and isn't built or
tested by CI.

What changes:

- **The current skill.** `SKILL.md` gains every rule and construct note
that the conversions since mid-September turned up. It ships three
scripts under `scripts/`: the `rst2myst.py` converter, the
`doctest_parity.py` coverage check, and `render_diff.py`, which moves
from the skill root with no content change.
- **Hard rule 4 matches #67432.** A converted page no longer keeps `..
doctest::` blocks or `>>>` prompts. Real ones become `{testcode}` plus
`{testoutput}`, and ones that can't run in CI become plain `python` and
`text` blocks, so `pytest-sphinx` owns every executed block. The
converter still emits a `{doctest}` fence for `.. doctest::`, and its
flag now points at that rewrite.
- **A status section.** It records which `.rst` sources remain: the
`*/api/` reference pages, the autosummary templates,
`_includes/rllib/new_api_stack.rst`, and
`ray-observability/reference/cli.rst`.
- **Lint fixes.** Ray's black reformats the two new scripts, and ruff
E731 turns one lambda into a `def`.

## Related issues

Follows #67432, which converted the last five pages that had `>>>`
prompts.

## Additional information

### Duplicate check

No open PR touches `doc/.claude/skills/rst-to-myst/`. I checked with `gh
pr list --state open` filtered on that path.

### Testing

- `python3 doc/.claude/skills/rst-to-myst/scripts/rst2myst.py
--selftest`: 80/80 cases pass, before and after formatting.
- `python3 doc/.claude/skills/rst-to-myst/scripts/doctest_parity.py
--selftest`: 7/7 cases pass.
- `pre-commit run --files` on every changed file passes, including ruff
and black.

`.buildkite/test.rules.txt` skips `doc/.claude/`, so this PR runs no
library tests.

This PR changes an agent skill, and it comes from a docs-team session.
It 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]>
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]>
dstrodtman added a commit that referenced this pull request Nov 2, 2026
#67639)

## Description

Stacked on #67429, which is stacked on #67426.

#67426 tells contributors not to add new notebooks, but other
contributor docs still offer the in-tree notebook flow as a way to
publish a new example. This PR removes those instructions and keeps only
what someone needs to maintain the two notebook examples that remain.

### What this PR changes

- `doc/source/ray-contribute/publishing-examples-legacy.md`: rewrites
the page as "Maintaining an in-tree notebook example." It keeps its file
name and its `publishing-examples-legacy` label, so no redirect is
needed.
- It names the two examples that still use the flow,
`serve/tutorials/video-analysis` and
`train/examples/transformers/transformer-reinforcement-learning`. These
are the only `working_dir: //doc/...` entries in
`release/release_tests.yaml`.
- It drops the steps for publishing a new notebook: setting up a working
directory, the `content/` layout, and wiring a toctree or
`examples.yml`. Neither remaining example uses the `content/` layout.
Each one has `README.ipynb`, a `README.md` copy, and `ci/`, and
`exclude_patterns` in `conf.py` decides which file renders.
- It drops the `orphan: true` advice. `conf.py` sets `orphan` on every
page an `examples.yml` gallery links to through
`collect_example_orphans()`.
- It keeps the cell-tag guidance from #67426, the CI test, the release
test, triggering it, and the pre-merge checks, all reworded for an
existing example. The `tests.sh` sample matches what both examples run.
The trigger example uses the real test name `video_analysis_pipeline`.
- `doc/source/ray-contribute/publishing-examples.md`: replaces "Two ways
to publish an example" with a description of the template-collections
flow. It says not to publish a new example as an in-tree notebook and
links the maintenance page.
- `doc/README.md`: replaces "Adding examples as MyST Markdown Notebooks"
with "Running in-tree notebooks." It says not to add new notebooks,
points to `docs.md`, and keeps the `RUN_NOTEBOOKS` instructions, which
`conf.py` still reads as `nb_execution_mode`. It drops the paragraph
that recommended notebooks for examples and a commented-out link to a
tutorial that no longer exists.
- `doc/source/ray-contribute/writing-code-snippets.md`: "When to use
*literalinclude*" said to use it for "an end-to-end example," which
conflicts with #67426's end-to-end guide, which CI doesn't test. It now
says "a longer example" and links `writing-e2e-guide`.
- `doc/source/core/objects/object-spilling.md`: turns a `{doctest}`
block into a plain `python` block. The block has no `>>>` prompt and no
target, so it ran nothing, and it was the last `{doctest}` block on a
documentation page. #67432 missed it because it searched for `>>>`.

## Related issues

Stacked on #67429 and #67426. Follows #67432, which converted the other
page doctests.

## Additional information

### Duplicate check

I searched open PRs for `publishing-examples-legacy`, `in-tree
notebook`, `RUN_NOTEBOOKS`, `object-spilling`, `writing-code-snippets`,
and changes to `doc/README.md`. No open PR rewrites the legacy page or
the README section. #66851 also edits `object-spilling.md`, and #65868
also edits `writing-code-snippets.md`, in other hunks. `git merge-tree`
reports no conflicts with either.

### Testing

- `pre-commit run --files` on the changed files passes, including the
check that links to files on master resolve.
- `python doc/test_prose_doctest_targets.py` passes: "73 listed pages;
every runnable page is accounted for."
- `rayci test-rules` at v0.51.0, the version `.rayciversion` pins,
passes.
- `vale` on the rewritten pages: no new alerts beyond a passive-voice
flag on an unchanged sentence. The alerts in `doc/README.md` are all on
lines this PR doesn't change.
- 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-example-test Opt into narrowly-scoped testing for docs example code. go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants