Repository navigation
[ci/doc] Generate API stubs without a full doc build; fail loudly - #64423
Conversation
There was a problem hiding this comment.
Code Review
This pull request decouples the API-doc consistency check from a full Sphinx HTML build by introducing a standalone API stub generation script (doc/source/api_autogen.py) and updating the CI linting process. It also adds unit tests for API resolution and duplicate detection policies. The review feedback highlights three key improvement opportunities: preventing false-positive build failures in api_autogen.py when stub files are already up-to-date, caching resolved objects in API.resolve() to avoid redundant dynamic import overhead, and using safe_getattr in custom Jinja filters to robustly handle missing attributes and None docstrings.
cf71bcb to
46f3cec
Compare
|
Heads-up on a follow-up that pairs with this PR: #64775 reserves the Once this PR lands and |
46f3cec to
e5fecf9
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit e5fecf9. Configure here.
The API-doc consistency check reads autosummary stub .rst files (the per-class method tables the hand-written API pages `.. include::`). Those stubs were produced only as a side effect of `make -C doc/ html`, so every Python-touching premerge PR paid for a full Sphinx render just to generate them. Extract the stub generation into doc/source/api_autogen.py, shared by the render and a standalone entry point: - conf.py imports the autogen file list, the filename map, and the custom autosummary Jinja filters from the new module (importing it registers the filters), keeping the render and the standalone path in lockstep. - generate_api_stubs() raises when generation produces no files, and _autogen_apis no longer swallows failures in a try/except + warning. A broken autogen step now fails the build instead of emitting an empty fixture the consistency check then reads as "nothing to do". - The standalone generator applies the shared absent-backend mock from api_mock_imports.py, so it imports the same optional-dependency modules the consistency check does and produces the same stub surface. - lint.sh's api_policy_check runs `python doc/source/api_autogen.py` instead of `make -C doc/ html`, removing the full render from the premerge check while preserving the contract guarantee. Stubs are generated after installing Ray so they reflect the checkout's source. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
1334bbe to
f4a7297
Compare
…eck (#65340) ## Why this change is needed The API-doc consistency check (`ci/ray_ci/doc/`) classifies a documented API as non-public when its canonical name resolves under a private module, keying on the `._internal.` segment in `API._is_private_name()`. Several public Ray Data APIs are re-exported into `ray.data.__all__` while their implementation lives in `_internal`, so the heuristic flags names that are legitimately public and correctly documented. Those false positives were suppressed with a per-team `doc_only_whitelist` — a hand-maintained list that had to grow by one entry every time a team re-exported another API from a private module. ## What this change does Reads the export instead of guessing from the path. A name that the documented module declares in its `__all__` is public regardless of where its implementation lives, so the new `API._is_public_reexport()` exempts it from the private-name rule and the list goes away. The exemption is deliberately narrow, so genuinely private symbols stay flagged: - **Only a public module's `__all__` counts.** A name documented through a private path (`ray.data._internal.foo.Bar`) keeps its verdict — a private module's `__all__` is not a public contract. - **An underscore leaf stays private** on either side of the re-export. `__all__` membership can never promote a `_foo` name. - **Module-attribute reachability alone changes nothing.** Absent an explicit `__all__` entry, the verdict is unchanged. Scope is limited to the resolve check's non-public classification (`split_resolvable_and_broken_doc_apis`). The "every `@PublicAPI` must be documented" check and the duplicate-documentation check are untouched, as is `API.is_public()` on the code side. ## Whitelist entries retired All seven `doc_only_whitelist` entries on the data team config: | Retired entry | Public name it's documented under | |---|---| | `ray.data._internal.compute.ActorPoolStrategy` | `ray.data.ActorPoolStrategy` | | `ray.data._internal.compute.TaskPoolStrategy` | `ray.data.TaskPoolStrategy` | | `ray.data._internal.execution.interfaces.execution_options.ExecutionOptions` | `ray.data.ExecutionOptions` | | `ray.data._internal.execution.interfaces.execution_options.ExecutionResources` | `ray.data.ExecutionResources` | | `ray.data._internal.logical.operators.n_ary_operator.MixStoppingCondition` | `ray.data.MixStoppingCondition` | | `ray.data._internal.random_config.RandomSeedConfig` | `ray.data.RandomSeedConfig` | | `ray.llm._internal.batch.processor.base.Processor` | `ray.data.llm.Processor` | Each is present in `ray.data.__all__` or `ray.data.llm.__all__`, and each is documented through its public `currentmodule` in `doc/source/data/api/`. None carries a `@Deprecated` annotation, so none relied on the whitelist for anything beyond the private-path suppression this change replaces. RLlib's `doc_only_whitelist` is a different case — instance attributes assigned in `setup()` that the import walk can't resolve — and is untouched. ## Related PRs - #64423 added the `doc_only_whitelist` workaround. - #64786 split the whitelists into permanent exemptions and tracked debt. ## Checks - [x] I've signed off every commit (`git commit --signoff`). - [x] I've made sure the tests are passing. - Testing Strategy - [x] Unit tests `ci/ray_ci/doc/test_api.py` gains coverage for the re-export case, for the same object documented through its private canonical path, and for the negative control — a class importable from the same public module but absent from its `__all__`, which must still be flagged. A private mock subpackage (`ci/ray_ci/doc/mock/_internal/`) provides the fixture so the test exercises the real `._internal.` code path rather than a spoofed `__module__`. Verified locally: the four `ci/ray_ci/doc` unit-test files pass (44 tests), and `pre-commit` is clean on the changed files. The end-to-end `api_policy_check` step needs a bazel-built Ray in the docbuild image, so the whitelist retirement is verified statically here (`__all__` membership and annotations read from source, per the table above) and premerge's `doc_api_policy_check` is the decisive check. --------- Signed-off-by: Douglas Strodtman <[email protected]>
…y-project#64423) ## Why The `doc: check API doc consistency` premerge step reads autosummary stub `.rst` files — the per-class method tables that the hand-written API pages `.. include::`. Those stubs are produced only as a side effect of `make -C doc/ html`, so **every Python-touching premerge PR pays for a full Sphinx render just to generate them**. Separately, the generation was wrapped in a `try/except` that downgraded any failure to a warning, so a broken autogen step silently produced an empty fixture the check then read as "nothing to do." This PR extracts stub generation into a standalone entry point and makes it fail loudly, so the check runs against a faithfully generated stub set without the full render. ## What Extracts the stub generation into `doc/source/api_autogen.py`, shared by the render and a standalone entry point: - **`conf.py`** imports the autogen file list (`AUTOGEN_FILES`), the filename map, and the custom autosummary Jinja filters from the new module (importing it registers the filters), keeping the render and the standalone path in lockstep. No behavior change to the render except the loud failure below. - **Fail loudly:** `generate_api_stubs()` raises when generation produces no files, and `conf.py` no longer swallows failures. A broken autogen step fails the build instead of emitting an empty fixture. - **Decouple:** `lint.sh`'s `api_policy_check` runs `python doc/source/api_autogen.py` instead of `make -C doc/ html`, removing the full render from the premerge check while preserving the contract guarantee. Stubs are generated *after* installing Ray so they reflect the checkout's source. The standalone path mirrors `sphinx-autogen` (a minimal `DummyApplication` with the project templates on the path), so it produces byte-identical stubs without the rest of the build. It applies the shared absent-backend mock from `doc/source/api_mock_imports.py` (introduced separately, see below), so the optional-dependency modules that the check imports are the same ones the generator sees. ## Relationship to ray-project#64808 The mock, whitelist, and doc-debt work that greened the check across all libraries — including `doc/source/api_mock_imports.py` and every `TEAM_API_CONFIGS` change — landed first in **ray-project#64808** and is now in `master`. This PR is rebased on top of it and **only consumes** the shared mock; it introduces none of that config. The diff here is exactly three files: `doc/source/api_autogen.py` (new), `doc/source/conf.py`, and `ci/lint/lint.sh`. ## Why data-only `AUTOGEN_FILES` is complete `AUTOGEN_FILES` is `["data/api/_autogen.rst"]`, and that is the full set the check needs, not a partial one. The consistency check's doc-side reader (`ci/ray_ci/doc/autodoc.py`) parses `.. autosummary::` directives **directly from the checked-in source**, following only explicit `.. include::` and `.. toctree::` edges. It descends into a *generated* stub only where a tracked page includes one — and only the `data` API pages do that (`dataset.rst` etc. `.. include::` the generated `ray.data.Dataset.rst` method tables). The other teams list their APIs with `.. autosummary::` directives in tracked source, which the check reads without any generated file. Two facts make this exact, independent of Ray version: - Running the real `Autodoc` traversal against a clean checkout, the only generated files it follows are the three `data` class stubs — which this generator produces. core / train / tune / serve / rllib follow zero generated files. - The method-table templates (`_templates/autosummary/class.rst`, `class_v2.rst`) emit only `.. autosummary::`, never `.. include::`/`.. toctree::`, so a generated stub never adds a new edge the traversal would follow. So the stubs `make html` generated for the other teams were never read by the check; dropping them changes nothing it verifies. (A follow-up would only be needed if a non-data team later adopts the include-a-generated-method-stub pattern.) ## Verification - **Rebase:** reduced to a single commit on current `master` (post-ray-project#64808). Final diff is the three files above, +217/−86. - **Static (local):** all changed modules `py_compile`; `pre-commit` passes on the changed files (trailing-whitespace, end-of-file, shellcheck on `lint.sh`, semgrep — ruff/black skip `doc/source/**` by Ray's config). - **Stub parity (local, earlier, against a matching Ray build):** the standalone script generated the same data stubs as the full render (82 files), the consistency check read them, and a genuine generation failure exited nonzero where the old code only warned. - **Decisive gate:** the `doc: check API doc consistency` premerge job runs `python ci/ray_ci/doc/cmd_check_api_discrepancy.py <checkout> ALL` on the docbuild image. Confirming its result on this PR before leaving draft. ## Risk / coordination `lint.sh` is a shared premerge surface and `conf.py` is the production render config. The functional change is the stub-generation source for the check (see the scope note above); the set of stubs the check actually reads is unchanged. Requesting doc-CI-owner review before this leaves draft. AI assistance was used to author these changes; every changed line was reviewed by the submitter. Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: 400Ping <[email protected]>
…eck (ray-project#65340) ## Why this change is needed The API-doc consistency check (`ci/ray_ci/doc/`) classifies a documented API as non-public when its canonical name resolves under a private module, keying on the `._internal.` segment in `API._is_private_name()`. Several public Ray Data APIs are re-exported into `ray.data.__all__` while their implementation lives in `_internal`, so the heuristic flags names that are legitimately public and correctly documented. Those false positives were suppressed with a per-team `doc_only_whitelist` — a hand-maintained list that had to grow by one entry every time a team re-exported another API from a private module. ## What this change does Reads the export instead of guessing from the path. A name that the documented module declares in its `__all__` is public regardless of where its implementation lives, so the new `API._is_public_reexport()` exempts it from the private-name rule and the list goes away. The exemption is deliberately narrow, so genuinely private symbols stay flagged: - **Only a public module's `__all__` counts.** A name documented through a private path (`ray.data._internal.foo.Bar`) keeps its verdict — a private module's `__all__` is not a public contract. - **An underscore leaf stays private** on either side of the re-export. `__all__` membership can never promote a `_foo` name. - **Module-attribute reachability alone changes nothing.** Absent an explicit `__all__` entry, the verdict is unchanged. Scope is limited to the resolve check's non-public classification (`split_resolvable_and_broken_doc_apis`). The "every `@PublicAPI` must be documented" check and the duplicate-documentation check are untouched, as is `API.is_public()` on the code side. ## Whitelist entries retired All seven `doc_only_whitelist` entries on the data team config: | Retired entry | Public name it's documented under | |---|---| | `ray.data._internal.compute.ActorPoolStrategy` | `ray.data.ActorPoolStrategy` | | `ray.data._internal.compute.TaskPoolStrategy` | `ray.data.TaskPoolStrategy` | | `ray.data._internal.execution.interfaces.execution_options.ExecutionOptions` | `ray.data.ExecutionOptions` | | `ray.data._internal.execution.interfaces.execution_options.ExecutionResources` | `ray.data.ExecutionResources` | | `ray.data._internal.logical.operators.n_ary_operator.MixStoppingCondition` | `ray.data.MixStoppingCondition` | | `ray.data._internal.random_config.RandomSeedConfig` | `ray.data.RandomSeedConfig` | | `ray.llm._internal.batch.processor.base.Processor` | `ray.data.llm.Processor` | Each is present in `ray.data.__all__` or `ray.data.llm.__all__`, and each is documented through its public `currentmodule` in `doc/source/data/api/`. None carries a `@Deprecated` annotation, so none relied on the whitelist for anything beyond the private-path suppression this change replaces. RLlib's `doc_only_whitelist` is a different case — instance attributes assigned in `setup()` that the import walk can't resolve — and is untouched. ## Related PRs - ray-project#64423 added the `doc_only_whitelist` workaround. - ray-project#64786 split the whitelists into permanent exemptions and tracked debt. ## Checks - [x] I've signed off every commit (`git commit --signoff`). - [x] I've made sure the tests are passing. - Testing Strategy - [x] Unit tests `ci/ray_ci/doc/test_api.py` gains coverage for the re-export case, for the same object documented through its private canonical path, and for the negative control — a class importable from the same public module but absent from its `__all__`, which must still be flagged. A private mock subpackage (`ci/ray_ci/doc/mock/_internal/`) provides the fixture so the test exercises the real `._internal.` code path rather than a spoofed `__module__`. Verified locally: the four `ci/ray_ci/doc` unit-test files pass (44 tests), and `pre-commit` is clean on the changed files. The end-to-end `api_policy_check` step needs a bazel-built Ray in the docbuild image, so the whitelist retirement is verified statically here (`__all__` membership and annotations read from source, per the table above) and premerge's `doc_api_policy_check` is the decisive check. --------- Signed-off-by: Douglas Strodtman <[email protected]> Signed-off-by: 400Ping <[email protected]>
…eck (ray-project#65340) ## Why this change is needed The API-doc consistency check (`ci/ray_ci/doc/`) classifies a documented API as non-public when its canonical name resolves under a private module, keying on the `._internal.` segment in `API._is_private_name()`. Several public Ray Data APIs are re-exported into `ray.data.__all__` while their implementation lives in `_internal`, so the heuristic flags names that are legitimately public and correctly documented. Those false positives were suppressed with a per-team `doc_only_whitelist` — a hand-maintained list that had to grow by one entry every time a team re-exported another API from a private module. ## What this change does Reads the export instead of guessing from the path. A name that the documented module declares in its `__all__` is public regardless of where its implementation lives, so the new `API._is_public_reexport()` exempts it from the private-name rule and the list goes away. The exemption is deliberately narrow, so genuinely private symbols stay flagged: - **Only a public module's `__all__` counts.** A name documented through a private path (`ray.data._internal.foo.Bar`) keeps its verdict — a private module's `__all__` is not a public contract. - **An underscore leaf stays private** on either side of the re-export. `__all__` membership can never promote a `_foo` name. - **Module-attribute reachability alone changes nothing.** Absent an explicit `__all__` entry, the verdict is unchanged. Scope is limited to the resolve check's non-public classification (`split_resolvable_and_broken_doc_apis`). The "every `@PublicAPI` must be documented" check and the duplicate-documentation check are untouched, as is `API.is_public()` on the code side. ## Whitelist entries retired All seven `doc_only_whitelist` entries on the data team config: | Retired entry | Public name it's documented under | |---|---| | `ray.data._internal.compute.ActorPoolStrategy` | `ray.data.ActorPoolStrategy` | | `ray.data._internal.compute.TaskPoolStrategy` | `ray.data.TaskPoolStrategy` | | `ray.data._internal.execution.interfaces.execution_options.ExecutionOptions` | `ray.data.ExecutionOptions` | | `ray.data._internal.execution.interfaces.execution_options.ExecutionResources` | `ray.data.ExecutionResources` | | `ray.data._internal.logical.operators.n_ary_operator.MixStoppingCondition` | `ray.data.MixStoppingCondition` | | `ray.data._internal.random_config.RandomSeedConfig` | `ray.data.RandomSeedConfig` | | `ray.llm._internal.batch.processor.base.Processor` | `ray.data.llm.Processor` | Each is present in `ray.data.__all__` or `ray.data.llm.__all__`, and each is documented through its public `currentmodule` in `doc/source/data/api/`. None carries a `@Deprecated` annotation, so none relied on the whitelist for anything beyond the private-path suppression this change replaces. RLlib's `doc_only_whitelist` is a different case — instance attributes assigned in `setup()` that the import walk can't resolve — and is untouched. ## Related PRs - ray-project#64423 added the `doc_only_whitelist` workaround. - ray-project#64786 split the whitelists into permanent exemptions and tracked debt. ## Checks - [x] I've signed off every commit (`git commit --signoff`). - [x] I've made sure the tests are passing. - Testing Strategy - [x] Unit tests `ci/ray_ci/doc/test_api.py` gains coverage for the re-export case, for the same object documented through its private canonical path, and for the negative control — a class importable from the same public module but absent from its `__all__`, which must still be flagged. A private mock subpackage (`ci/ray_ci/doc/mock/_internal/`) provides the fixture so the test exercises the real `._internal.` code path rather than a spoofed `__module__`. Verified locally: the four `ci/ray_ci/doc` unit-test files pass (44 tests), and `pre-commit` is clean on the changed files. The end-to-end `api_policy_check` step needs a bazel-built Ray in the docbuild image, so the whitelist retirement is verified statically here (`__all__` membership and annotations read from source, per the table above) and premerge's `doc_api_policy_check` is the decisive check. --------- Signed-off-by: Douglas Strodtman <[email protected]>

Why
The
doc: check API doc consistencypremerge step reads autosummary stub.rstfiles — the per-class method tables that the hand-written API pages.. include::. Those stubs are produced only as a side effect ofmake -C doc/ html, so every Python-touching premerge PR pays for a full Sphinx render just to generate them. Separately, the generation was wrapped in atry/exceptthat downgraded any failure to a warning, so a broken autogen step silently produced an empty fixture the check then read as "nothing to do."This PR extracts stub generation into a standalone entry point and makes it fail loudly, so the check runs against a faithfully generated stub set without the full render.
What
Extracts the stub generation into
doc/source/api_autogen.py, shared by the render and a standalone entry point:conf.pyimports the autogen file list (AUTOGEN_FILES), the filename map, and the custom autosummary Jinja filters from the new module (importing it registers the filters), keeping the render and the standalone path in lockstep. No behavior change to the render except the loud failure below.generate_api_stubs()raises when generation produces no files, andconf.pyno longer swallows failures. A broken autogen step fails the build instead of emitting an empty fixture.lint.sh'sapi_policy_checkrunspython doc/source/api_autogen.pyinstead ofmake -C doc/ html, removing the full render from the premerge check while preserving the contract guarantee. Stubs are generated after installing Ray so they reflect the checkout's source.The standalone path mirrors
sphinx-autogen(a minimalDummyApplicationwith the project templates on the path), so it produces byte-identical stubs without the rest of the build. It applies the shared absent-backend mock fromdoc/source/api_mock_imports.py(introduced separately, see below), so the optional-dependency modules that the check imports are the same ones the generator sees.Relationship to #64808
The mock, whitelist, and doc-debt work that greened the check across all libraries — including
doc/source/api_mock_imports.pyand everyTEAM_API_CONFIGSchange — landed first in #64808 and is now inmaster. This PR is rebased on top of it and only consumes the shared mock; it introduces none of that config. The diff here is exactly three files:doc/source/api_autogen.py(new),doc/source/conf.py, andci/lint/lint.sh.Why data-only
AUTOGEN_FILESis completeAUTOGEN_FILESis["data/api/_autogen.rst"], and that is the full set the check needs, not a partial one. The consistency check's doc-side reader (ci/ray_ci/doc/autodoc.py) parses.. autosummary::directives directly from the checked-in source, following only explicit.. include::and.. toctree::edges. It descends into a generated stub only where a tracked page includes one — and only thedataAPI pages do that (dataset.rstetc... include::the generatedray.data.Dataset.rstmethod tables). The other teams list their APIs with.. autosummary::directives in tracked source, which the check reads without any generated file.Two facts make this exact, independent of Ray version:
Autodoctraversal against a clean checkout, the only generated files it follows are the threedataclass stubs — which this generator produces. core / train / tune / serve / rllib follow zero generated files._templates/autosummary/class.rst,class_v2.rst) emit only.. autosummary::, never.. include::/.. toctree::, so a generated stub never adds a new edge the traversal would follow.So the stubs
make htmlgenerated for the other teams were never read by the check; dropping them changes nothing it verifies. (A follow-up would only be needed if a non-data team later adopts the include-a-generated-method-stub pattern.)Verification
master(post-[ci/doc] Green the API-doc consistency check across all libraries #64808). Final diff is the three files above, +217/−86.py_compile;pre-commitpasses on the changed files (trailing-whitespace, end-of-file, shellcheck onlint.sh, semgrep — ruff/black skipdoc/source/**by Ray's config).doc: check API doc consistencypremerge job runspython ci/ray_ci/doc/cmd_check_api_discrepancy.py <checkout> ALLon the docbuild image. Confirming its result on this PR before leaving draft.Risk / coordination
lint.shis a shared premerge surface andconf.pyis the production render config. The functional change is the stub-generation source for the check (see the scope note above); the set of stubs the check actually reads is unchanged. Requesting doc-CI-owner review before this leaves draft.AI assistance was used to author these changes; every changed line was reviewed by the submitter.