Skip to content

test(core): add cuda.core.__all__ vs public docs consistency check#2347

Open
aryanputta wants to merge 2 commits into
NVIDIA:mainfrom
aryanputta:test/api-docs-consistency-2326
Open

test(core): add cuda.core.__all__ vs public docs consistency check#2347
aryanputta wants to merge 2 commits into
NVIDIA:mainfrom
aryanputta:test/api-docs-consistency-2326

Conversation

@aryanputta

Copy link
Copy Markdown
Contributor

Description

Closes #2326.

Adds cuda_core/tests/test_api_docs_consistency.py, the follow-on consistency check requested in the #2300 review.

What it checks

  • test_all_exports_resolve: every name in cuda.core.__all__ resolves via hasattr (the stale-name guard suggested in the review).
  • test_public_symbols_are_documented: fails with "public by cuda.core.__all__ but missing from public docs (api.rst)" plus the offending names.
  • test_documented_symbols_are_exported: fails with "documented as public in api.rst but not exported by cuda.core.__all__" plus the offending names.

How the docs are parsed

  • .. module:: and .. currentmodule:: directives are tracked, so only autosummary entries and .. data:: directives active under cuda.core count. Entries under cuda.core.utils or cuda.core.texture are excluded automatically.
  • Dotted entries such as graph.Graph or checkpoint.Process are submodule namespaces, not flat cuda.core names, and are excluded.
  • Symbols documented in api_private.rst are accepted as documented by their trailing name, so returned helpers such as _device_resources.DeviceResources do not fail the public-docs direction.

Ordering with #2300

The tests skip when cuda.core.__all__ is not defined, so this is safe to land before #2300 and activates once #2300 merges. The docs fixture also skips when docs sources are unavailable (installed-wheel test runs).

Validation

I do not have a CUDA-capable machine available, so I validated with a stubbed cuda.core module against the real RST files in this repo:

ruff check and ruff format pass.

Closes NVIDIA#2326.

Parses docs/source/api.rst (autosummary entries and data directives while
cuda.core is the active module) and compares the flat public names against
cuda.core.__all__ in both directions. Dotted entries such as graph.Graph or
checkpoint.Process are submodule namespaces and are excluded. Symbols
documented in api_private.rst are accepted as documented so returned-helper
docs do not fail the check.

The tests skip when cuda.core.__all__ is not defined, so this lands
independently of NVIDIA#2300 and activates once NVIDIA#2300 merges. Also adds the
__all__-names-resolve guard suggested in the NVIDIA#2300 review.

Signed-off-by: Aryan <aryansputta@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Jul 12, 2026
@copy-pr-bot

copy-pr-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

/ok to test

@mdboom, there was an error processing your request: E1

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/1/

@mdboom

mdboom commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

/ok to test 1fc21b2

@github-actions

Copy link
Copy Markdown

@mdboom mdboom 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.

The main change required is that the scope of this is too limited.

It would also be worthwhile verifying that this tests what we think it does by (in another PR) adding some changes that this is expected to catch to confirm that they are in fact caught.

I also think this should land the __all__ into cuda.core here (again, to confirm it's working) rather than waiting for #2300 to add it.

Comment on lines +10 to +12
are accepted as documented. Dotted entries such as ``graph.Graph`` or
``checkpoint.Process`` describe submodule namespaces, not the flat
``cuda.core`` namespace, and are excluded from the comparison.

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.

These should be included (as well as cuda.core.system).

Any __init__.py inside of a public (non _-prefixed) submodule is public API. Currently, graph, system, texture and utils, though more may be added in the future so the test should adapt automatically.

Today, only system has its own separate API .rst page (which is fine). I would argue the other submodules should have their own .rst page as well. (And we could do that refactor here).

@aryanputta

Copy link
Copy Markdown
Contributor Author

The main change required is that the scope of this is too limited.

It would also be worthwhile verifying that this tests what we think it does by (in another PR) adding some changes that this is expected to catch to confirm that they are in fact caught.

I also think this should land the __all__ into cuda.core here (again, to confirm it's working) rather than waiting for #2300 to add it.

Can you assign this to me, but will work on this today.

…bpackages

Addresses review feedback that the consistency check was too narrow:

- Define cuda.core.__all__ (flat public namespace) so the check runs instead
  of skipping, and add an aggregated __all__ to cuda.core.graph derived from
  its star-imported submodules.
- Auto-discover public subpackages from cuda.core.__path__ (graph, system,
  texture, utils, and any added later; the internal cuNN wheel shims are
  excluded) and assert each defines a fully resolvable __all__.
- Cross-check each documented subpackage's __all__ against api.rst, handling
  both the dotted (graph.Graph) and flat (currentmodule) doc conventions.
  system is documented in api_nvml.rst, so its doc cross-check is skipped.
@aryanputta

Copy link
Copy Markdown
Contributor Author

Hello @mdboom, thank you for the review. I have addressed both points.

  • Landed __all__ into cuda.core in this PR so the check runs against a real export surface instead of skipping. I also added an aggregated __all__ to cuda.core.graph (built from its star-imported submodules, so it cannot drift); system, texture, and utils already defined one.
  • Widened the scope: the test now auto-discovers public subpackages from cuda.core.__path__ (the internal cuNN wheel shims are excluded), asserts each defines a fully resolvable __all__, and cross-checks each documented subpackage against api.rst, handling both the dotted (graph.Graph) and flat (currentmodule) doc conventions. system is documented in api_nvml.rst and has a runtime-conditional __all__, so its doc cross-check is skipped while it is still verified for a well-formed __all__.

On confirming the check actually catches regressions: I prepared a separate branch that injects one deliberate discrepancy (a symbol documented in api.rst that nothing exports). test_documented_symbols_are_exported fails on it as expected while the rest of the suite stays green: https://github.com/aryanputta/cuda-python/tree/test/api-docs-consistency-demo-2326 . I can open that as a follow-up PR once this one lands, or fold a permanent negative test in here if you prefer. Please let me know which you would like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEA]: Add a consistency check for cuda.core.__all__ vs cuda_core/docs/source/api.rst

2 participants