Fix docs CI: use griffe for static source parsing #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Documentation | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: pip install griffe jinja2 | |
| - name: Build documentation | |
| run: | | |
| mkdir -p docs | |
| python << 'SCRIPT' | |
| import griffe | |
| from pathlib import Path | |
| import html | |
| loader = griffe.GriffeLoader(search_paths=["src"]) | |
| # Load only the modules we want, ignore errors | |
| modules_to_doc = ["nvidia_codec"] | |
| output = ['<!DOCTYPE html><html><head>', | |
| '<title>nvidia-codec API Reference</title>', | |
| '<style>', | |
| 'body { font-family: system-ui, sans-serif; max-width: 900px; margin: 0 auto; padding: 2rem; line-height: 1.6; }', | |
| 'pre { background: #f5f5f5; padding: 1rem; overflow-x: auto; border-radius: 4px; }', | |
| 'code { background: #f5f5f5; padding: 0.2em 0.4em; border-radius: 3px; }', | |
| '.docstring { margin-left: 1rem; color: #444; }', | |
| 'h1 { border-bottom: 2px solid #333; } h2, h3, h4 { border-bottom: 1px solid #ddd; padding-bottom: 0.3em; }', | |
| '.sig { color: #666; font-family: monospace; }', | |
| '</style></head><body>', | |
| '<h1>nvidia-codec API Reference</h1>'] | |
| def render_obj(obj, level=2): | |
| lines = [] | |
| h = f"h{min(level, 6)}" | |
| name = obj.name | |
| if hasattr(obj, 'signature'): | |
| sig = str(obj.signature) if obj.signature else "()" | |
| lines.append(f"<{h}>{html.escape(name)}<span class='sig'>{html.escape(sig)}</span></{h}>") | |
| else: | |
| lines.append(f"<{h}>{html.escape(name)}</{h}>") | |
| if obj.docstring: | |
| lines.append(f"<div class='docstring'><pre>{html.escape(obj.docstring.value)}</pre></div>") | |
| # Render members | |
| if hasattr(obj, 'members'): | |
| for member in obj.members.values(): | |
| if not member.name.startswith('_') or member.name in ('__init__',): | |
| lines.extend(render_obj(member, level + 1)) | |
| return lines | |
| try: | |
| mod = loader.load("nvidia_codec", try_relative_path=False) | |
| output.extend(render_obj(mod)) | |
| except Exception as e: | |
| output.append(f"<p>Error loading module: {html.escape(str(e))}</p>") | |
| output.append('</body></html>') | |
| Path("docs/index.html").write_text('\n'.join(output)) | |
| print("Documentation generated successfully") | |
| SCRIPT | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: docs | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |