fix: Early codec support check to avoid cryptic CUError on unsupporte… #14
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: Build documentation | |
| run: | | |
| mkdir -p docs | |
| python << 'SCRIPT' | |
| import ast | |
| from pathlib import Path | |
| import html as html_mod | |
| def get_docstring(node): | |
| return ast.get_docstring(node) or "" | |
| def get_signature(node): | |
| if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): | |
| return "" | |
| args = [] | |
| for arg in node.args.args: | |
| args.append(arg.arg) | |
| return f"({', '.join(args)})" | |
| def parse_file(filepath): | |
| with open(filepath) as f: | |
| tree = ast.parse(f.read()) | |
| return tree | |
| def render_module(filepath, module_name, level=2): | |
| lines = [] | |
| tree = parse_file(filepath) | |
| h = f"h{min(level, 6)}" | |
| # Module docstring | |
| lines.append(f"<{h}>{html_mod.escape(module_name)}</{h}>") | |
| doc = get_docstring(tree) | |
| if doc: | |
| lines.append(f"<div class='docstring'><pre>{html_mod.escape(doc)}</pre></div>") | |
| # Classes and functions | |
| for node in ast.iter_child_nodes(tree): | |
| if isinstance(node, ast.ClassDef) and not node.name.startswith('_'): | |
| lines.append(f"<h{min(level+1, 6)}>class {html_mod.escape(node.name)}</h{min(level+1, 6)}>") | |
| doc = get_docstring(node) | |
| if doc: | |
| lines.append(f"<div class='docstring'><pre>{html_mod.escape(doc)}</pre></div>") | |
| # Methods | |
| for item in ast.iter_child_nodes(node): | |
| if isinstance(item, ast.FunctionDef) and (not item.name.startswith('_') or item.name == '__init__'): | |
| sig = get_signature(item) | |
| lines.append(f"<h{min(level+2, 6)}>{html_mod.escape(item.name)}<span class='sig'>{html_mod.escape(sig)}</span></h{min(level+2, 6)}>") | |
| doc = get_docstring(item) | |
| if doc: | |
| lines.append(f"<div class='docstring'><pre>{html_mod.escape(doc)}</pre></div>") | |
| elif isinstance(node, ast.FunctionDef) and not node.name.startswith('_'): | |
| sig = get_signature(node) | |
| lines.append(f"<h{min(level+1, 6)}>{html_mod.escape(node.name)}<span class='sig'>{html_mod.escape(sig)}</span></h{min(level+1, 6)}>") | |
| doc = get_docstring(node) | |
| if doc: | |
| lines.append(f"<div class='docstring'><pre>{html_mod.escape(doc)}</pre></div>") | |
| return lines | |
| 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; white-space: pre-wrap; } | |
| 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, h5, h6 { border-bottom: 1px solid #ddd; padding-bottom: 0.3em; } | |
| .sig { color: #666; font-family: monospace; } | |
| </style></head><body> | |
| <h1>nvidia-codec API Reference</h1>'''] | |
| # Document key modules | |
| modules = [ | |
| ("src/nvidia_codec/__init__.py", "nvidia_codec"), | |
| ("src/nvidia_codec/utils/__init__.py", "nvidia_codec.utils"), | |
| ("src/nvidia_codec/utils/player.py", "nvidia_codec.utils.player"), | |
| ("src/nvidia_codec/core/decode.py", "nvidia_codec.core.decode"), | |
| ] | |
| for filepath, name in modules: | |
| if Path(filepath).exists(): | |
| output.extend(render_module(filepath, name)) | |
| 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 |