Skip to content

feat(api-style): Add badge system for standard Python API entries#10

Merged
tony merged 7 commits intomainfrom
api-styling
Apr 6, 2026
Merged

feat(api-style): Add badge system for standard Python API entries#10
tony merged 7 commits intomainfrom
api-styling

Conversation

@tony
Copy link
Copy Markdown
Member

@tony tony commented Apr 6, 2026

Summary

  • Adds gp_sphinx.api_style Sphinx extension that injects type and modifier badges into standard Python domain entries (functions, classes, methods, properties, attributes, data, exceptions)
  • Ships complete CSS with gas- prefix, 8 distinct type colors (function=blue, class=indigo, method=cyan, property=teal, attribute=slate, data=grey, exception=rose, type=violet), light/dark mode, Furo integration
  • Mirrors the badge visual language from sphinx-autodoc-pytest-fixtures (spf- prefix) so API pages and fixture pages look consistent

Architecture

Pure doctree transform — hooks into doctree-resolved, walks addnodes.desc nodes, detects modifiers from desc_sig_keyword nodes and deprecation from versionmodified, injects badge groups. No directive or documenter overrides, so cross-references and object IDs are preserved.

Badge types

Badge Style Detected from
function, class, method, property, attribute, data, exception Filled, type-specific color desc.objtype
async Purple outlined desc_sig_keyword("async")
classmethod Amber outlined desc_sig_keyword("classmethod")
staticmethod Grey outlined desc_sig_keyword("static")
abstract Indigo outlined desc_sig_keyword("abstractmethod")
final Emerald outlined desc_sig_keyword("final")
deprecated Red/grey outlined versionmodified(type='deprecated')

Files

Extension (packages/gp-sphinx/src/gp_sphinx/api_style/):

  • __init__.pysetup(), CSS registration, abbreviation visitor
  • _css.py — CSS class constants (gas-* prefix)
  • _badges.py — Badge group builder with canonical ordering
  • _transforms.py — Doctree-resolved handler, modifier/deprecated detection
  • _static/css/api_style.css — Full CSS token system, light/dark, Furo integration

Tests (tests/ext/api_style/): 37 unit tests + 11 doctests

Docs (docs/packages/api-styling.md): Live demo page with synthetic API module

Bugfixes included

  • Fix nested desc traversal so methods get their own objtype (not parent class)
  • Fix deprecated detection to exclude nested desc nodes (class doesn't inherit method's deprecation)
  • Fix worktree-safe doctest in docs/_ext/package_reference.py

Test plan

  • uv run ruff check . --fix --show-fixes — all checks passed
  • uv run ruff format . — no changes
  • uv run mypy src tests — no issues in 33 source files
  • uv run pytest --reruns 0 — 711 passed, 3 skipped
  • uv run sphinx-build -b html docs docs/_build/html — build succeeded
  • Visual review of badge rendering on demo page

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 6, 2026

Codecov Report

❌ Patch coverage is 94.63519% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.17%. Comparing base (c36fbd6) to head (dee1c36).

Files with missing lines Patch % Lines
...-style/src/sphinx_autodoc_api_style/_transforms.py 84.41% 12 Missing ⚠️
docs/_ext/gas_demo_api.py 75.86% 7 Missing ⚠️
scripts/ci/package_tools.py 20.00% 4 Missing ⚠️
...api-style/src/sphinx_autodoc_api_style/__init__.py 92.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #10      +/-   ##
==========================================
+ Coverage   88.82%   89.17%   +0.35%     
==========================================
  Files          72       78       +6     
  Lines        7111     7576     +465     
==========================================
+ Hits         6316     6756     +440     
- Misses        795      820      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

tony added 6 commits April 6, 2026 11:43
why: Provide type and modifier badges for standard Python autodoc entries
what:
- Add _badges.py with badge group builder for type/modifier badges
- Add _transforms.py with doctree-resolved handler and toolbar injection
- Add _css.py with CSS class name constants
- Add api_style.css with card containers, badge colors, responsive layout
- Add __init__.py with Sphinx extension setup
- Add pyproject.toml, README.md, py.typed
why: Verify badge building, modifier detection, and toolbar injection
what:
- Add tests for _CSS constants and obj_type helper
- Add tests for build_badge_group (types, modifiers, tooltips, accessibility)
- Add tests for _detect_modifiers and _detect_deprecated
- Add tests for _inject_badges (toolbar, viewcode, headerlink handling)
- Add tests for on_doctree_resolved event handler
why: Make the new package discoverable by uv, ruff, mypy, and pytest
what:
- Add workspace source and dev dependency
- Add known-first-party and per-file-ignores for ruff
- Add testpaths entry for pytest doctest collection
- Update test_package_reference assertions for new package
why: Ensure the new package installs and imports correctly in CI
what:
- Add smoke_sphinx_autodoc_api_style function in package_tools.py
- Add sphinx-autodoc-api-style to smoke test matrix in tests.yml
why: Showcase badge types, modifier badges, and card styling with live examples
what:
- Add gas_demo_api.py with synthetic objects exercising every badge
- Add sphinx-autodoc-api-style.md package page with badge reference
- Wire extension into docs/conf.py
- Update package index and redirects
@tony tony marked this pull request as ready for review April 6, 2026 16:46
@tony tony merged commit e96bd89 into main Apr 6, 2026
32 checks passed
@tony tony deleted the api-styling branch April 6, 2026 16:50
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.

2 participants