-
Notifications
You must be signed in to change notification settings - Fork 1
131 lines (113 loc) · 4.93 KB
/
docs.yml
File metadata and controls
131 lines (113 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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