Skip to content

DOC improve API reference accuracy, structure, and readability#1469

Merged
romanlutz merged 4 commits intomicrosoft:mainfrom
biefan:docs/api-gen-include-empty-modules-653
Mar 16, 2026
Merged

DOC improve API reference accuracy, structure, and readability#1469
romanlutz merged 4 commits intomicrosoft:mainfrom
biefan:docs/api-gen-include-empty-modules-653

Conversation

@biefan
Copy link
Copy Markdown
Contributor

@biefan biefan commented Mar 14, 2026

Summary

This updates build_scripts/gen_api_md.py and build_scripts/pydoc2json.py to make generated API docs more complete, accurate, and readable.

What changed

gen_api_md.py — major refactor:

  • Generate pages only for top-level public modules (reduced from 324 pages to ~28), eliminating duplicate content where submodules re-export the same
    classes as their parent.
  • Recursively expand pure-aggregate modules (e.g. pyrit.executor) into their children that have actual API surface.
  • Resolve aliases to full class/function definitions using a definition index, so re-exported classes render with full documentation instead of bare
    "Alias of X" stubs.
  • Filter out external imports (stdlib, third-party) from rendered pages — only show members actually defined in each module's tree.
  • Exclude pyrit.backend from API docs (__all__ = [], exports nothing).
  • Simplify sidebar headings to show only class/function names (no type signatures), with full signatures in code blocks below.
  • Wrap doctest-style >>> examples in code fences for proper rendering.
  • Base member counts in logs and index preview on rendered kinds only (class/function).

pydoc2json.py — alias resolution fix:

  • Add _resolve_alias_from_source fallback using griffe.visit() to parse individual .py files when griffe cannot resolve aliases due to missing
    __init__.py in namespace packages (e.g. pyrit.datasets.seed_datasets).

Banner modules marked private:

  • pyrit/cli/banner.pypyrit/cli/_banner.py
  • pyrit/cli/banner_assets.pypyrit/cli/_banner_assets.py
  • Updated all imports and mock patch paths.

doc/myst.yml TOC updated to match generated pages.

Why

  • Fixes missing module pages that caused broken links from doc/api/index.md.
  • Eliminates duplicate API content (same class appearing on parent and submodule pages).
  • Resolves previously-stubbed classes (SeedDatasetProvider, TextJailBreak, scorers, targets) to full documentation.
  • Cleans up the sidebar for better navigation.
  • Marks internal CLI modules as private per Python convention.

Validation

  • uv run --with ruff ruff check build_scripts/gen_api_md.py build_scripts/pydoc2json.py
  • pytest tests/unit/cli/test_banner.py tests/unit/cli/test_pyrit_shell.py — 70 tests pass
  • Local doc site build and visual inspection

Fixes #653

Signed-off-by: biefan <70761325+biefan@users.noreply.github.com>
@biefan
Copy link
Copy Markdown
Contributor Author

biefan commented Mar 14, 2026

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Contributor

@romanlutz romanlutz left a comment

Choose a reason for hiding this comment

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

Looks good! Just want to try it out locally before merging

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the documentation build script that generates MyST API reference markdown from griffe JSON so that re-exported names (aliases) are represented and modules with no detected public members are handled more explicitly.

Changes:

  • Add alias rendering and an “Aliases” section to per-module API pages.
  • Generate per-module pages for all collected modules and show an explicit “no public API members” message when empty.
  • Improve index previews to include functions and aliases (not just classes), with a fallback message for empty modules.

You can also share your feedback on Copilot code review. Take the survey.

@romanlutz romanlutz changed the title docs: generate API pages for empty modules and render aliases DOC generate API pages for empty modules and render aliases Mar 15, 2026
romanlutz and others added 2 commits March 15, 2026 06:48
The log message and index preview '(N total)' suffix previously used
len(members), which includes nested submodules. This made the counts
misleading since render_module() only renders classes, functions, and
aliases.

Now both the per-module log line and the index preview count only
the kinds that are actually rendered.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Major improvements to gen_api_md.py:
- Only generate pages for top-level public modules, not every nested
  submodule (324 pages -> ~28 pages)
- Recursively expand pure-aggregate modules (e.g. pyrit.executor) into
  their children that have actual API surface
- Resolve aliases to full class/function definitions using the
  definition index, eliminating the separate Aliases section
- Filter out external imports (stdlib, third-party) from rendered pages
- Exclude pyrit.backend from API docs (exports nothing)
- Base member counts on rendered kinds only (class/function)

Fix pydoc2json.py alias resolution:
- Add _resolve_alias_from_source fallback using griffe.visit() to parse
  individual .py files when griffe cannot resolve aliases due to missing
  __init__.py in namespace packages (e.g. pyrit.datasets.seed_datasets)

Rename banner modules to private:
- pyrit/cli/banner.py -> pyrit/cli/_banner.py
- pyrit/cli/banner_assets.py -> pyrit/cli/_banner_assets.py
- Update all imports and mock patch paths

Update doc/myst.yml TOC to match generated pages.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@romanlutz
Copy link
Copy Markdown
Contributor

romanlutz commented Mar 16, 2026

While trying this out I had a number of additional thoughts and kept updating until I was happy. I hope you don't mind. I figured since this addresses an issue I initially filed it's probably fine.

left sidebar:
image

right sidebar:
image

code samples in api ref:
image

- Function/class headings now show only the name (no types/signatures)
  so the right sidebar stays clean and scannable
- Full signatures are rendered in a code block below the heading
- Class headings show bases on a separate line instead of in the heading
- Doctest-style examples (>>> lines) are wrapped in python code fences
  to prevent broken markdown rendering

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@biefan
Copy link
Copy Markdown
Contributor Author

biefan commented Mar 16, 2026

Ini telah ditemui dan diperbaiki oleh CODEX sendiri. Saya akan terus menghantar permintaan tarik kepada CODEX.

@romanlutz romanlutz changed the title DOC generate API pages for empty modules and render aliases DOC improve API reference accuracy, structure, and readability Mar 16, 2026
@romanlutz romanlutz merged commit 891919e into microsoft:main Mar 16, 2026
38 checks passed
riyosha pushed a commit to riyosha/PyRIT that referenced this pull request Mar 24, 2026
…t#1469)

Signed-off-by: biefan <70761325+biefan@users.noreply.github.com>
Co-authored-by: Roman Lutz <romanlutz13@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOC API reference has missing or malformed content

3 participants