Skip to content

Commit 4f184c4

Browse files
author
Colin Rothwell
committed
makedoc now documents all methods
make doc documents all methods, even those wrapped in classes. Classes within classes are not supported, however. It also adds a link to the top of the page after each modules name, to make browsing easier. It also doesn't add the colon and none after undocumented items.
1 parent 4a679cc commit 4f184c4

File tree

2 files changed

+109
-86
lines changed

2 files changed

+109
-86
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.pyc
2+
.DS_Store

tools/makedoc.py

100644100755
Lines changed: 108 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,108 @@
1-
import sys
2-
sys.path.insert(0, '..')
3-
import web
4-
import inspect
5-
6-
modules = [
7-
'web.application',
8-
'web.contrib.template',
9-
'web.db',
10-
'web.debugerror',
11-
'web.form',
12-
'web.http',
13-
'web.httpserver',
14-
'web.net',
15-
'web.session',
16-
'web.template',
17-
'web.utils',
18-
'web.webapi',
19-
'web.webopenid',
20-
'web.wsgi'
21-
]
22-
23-
qstart = '<code class="head">'
24-
qend = '</code>'
25-
26-
def process_func(name, f):
27-
print qstart + name + inspect.formatargspec(*inspect.getargspec(f)) + qend + ': '
28-
print inspect.getdoc(f)
29-
print
30-
31-
def process_class(name, cls):
32-
bases = [b.__name__ for b in cls.__bases__]
33-
if bases:
34-
name = name + '(' + ",".join(bases) + ')'
35-
36-
print qstart + 'class ' + name + qend + ': '
37-
print inspect.getdoc(cls)
38-
print
39-
40-
def process_storage(name, d):
41-
print qstart + name + qend + ': '
42-
print d['__doc__']
43-
44-
def process_mod(name, mod):
45-
print '<a name="%s"></a>' % name
46-
print '##', name
47-
print
48-
49-
all = getattr(mod, '__all__', None)
50-
51-
for k, v in inspect.getmembers(mod):
52-
if k.startswith('_'):
53-
continue
54-
55-
if inspect.getmodule(v) == mod:
56-
if inspect.isclass(v):
57-
process_class(k, v)
58-
elif inspect.isfunction(v):
59-
process_func(k, v)
60-
61-
# specical case for generating docs for web.ctx and web.config
62-
elif all and k in all and isinstance(v, (web.storage, web.threadeddict)) and hasattr(v, '__doc__'):
63-
process_storage(k, v)
64-
65-
def print_css():
66-
print
67-
print '<style type="text/css">'
68-
print ' #content {margin-left: 20px;}'
69-
print ' .head {margin-left: -20px;}'
70-
print ' h2 {margin-left: -20px;}'
71-
print '</style>'
72-
print
73-
74-
def main():
75-
for name in modules:
76-
print '* <a href="#%s">%s</a>' %(name, name)
77-
print
78-
79-
for name in modules:
80-
mod = __import__(name, {}, {}, 'x')
81-
process_mod(name, mod)
82-
83-
print_css()
84-
85-
if __name__ == '__main__':
86-
main()
1+
import sys
2+
sys.path.insert(0, '..')
3+
import web
4+
import inspect
5+
6+
modules = [
7+
'web.application',
8+
'web.contrib.template',
9+
'web.db',
10+
'web.debugerror',
11+
'web.form',
12+
'web.http',
13+
'web.httpserver',
14+
'web.net',
15+
'web.session',
16+
'web.template',
17+
'web.utils',
18+
'web.webapi',
19+
'web.webopenid',
20+
'web.wsgi'
21+
]
22+
23+
24+
qstart = '<code class="head">'
25+
qend = '</code>'
26+
27+
func_start = '<div style="margin-left:%dpx">'
28+
func_end = '</div>'
29+
30+
tab_width = 20 #width for tabs in px
31+
32+
def process_func(name, f, tablevel=1):
33+
if tablevel != 1: print func_start % (tablevel * tab_width)
34+
sys.stdout.write(qstart + name + inspect.formatargspec(*inspect.getargspec(f)) + qend)
35+
doc = inspect.getdoc(f)
36+
if not doc is None:
37+
print ": "
38+
print doc
39+
print
40+
if tablevel != 1: print func_end
41+
print
42+
43+
def process_class(name, cls):
44+
bases = [b.__name__ for b in cls.__bases__]
45+
if bases:
46+
name = name + '(' + ",".join(bases) + ')'
47+
48+
sys.stdout.write(qstart + 'class ' + name + qend)
49+
doc = inspect.getdoc(cls)
50+
if not doc is None:
51+
print ': '
52+
print inspect.getdoc(cls)
53+
print
54+
methods = [(m, getattr(cls, m)) for m in dir(cls)
55+
if not m.startswith('_') and inspect.ismethod(getattr(cls, m))]
56+
#Possible todo: see if code is faster with the get method in the rendering
57+
#loop.
58+
for m in methods: process_func(m[0], m[1], 2)
59+
60+
def process_storage(name, d):
61+
print qstart + name + qend + ': '
62+
print d['__doc__']
63+
64+
def process_mod(name, mod):
65+
print '<a name="%s"></a>' % name
66+
print '##', name
67+
print '<a href="#top">Back to top</a>'
68+
print
69+
70+
all = getattr(mod, '__all__', None)
71+
72+
for k, v in inspect.getmembers(mod):
73+
if k.startswith('_'):
74+
continue
75+
76+
if inspect.getmodule(v) == mod:
77+
if inspect.isclass(v):
78+
process_class(k, v)
79+
elif inspect.isfunction(v):
80+
process_func(k, v)
81+
82+
# specical case for generating docs for web.ctx and web.config
83+
elif all and k in all and isinstance(v, (web.storage, web.threadeddict)) and hasattr(v, '__doc__'):
84+
process_storage(k, v)
85+
86+
def print_css():
87+
print
88+
print '<style type="text/css">'
89+
print ' #content {margin-left: %dpx;}'% (tab_width)
90+
print ' .head {margin-left: -20px;}'
91+
print ' h2 {margin-left: -20px;}'
92+
print '</style>'
93+
print
94+
95+
def main():
96+
print '<a name="top"></a>'
97+
for name in modules:
98+
print '* <a href="#%s">%s</a>' %(name, name)
99+
print
100+
101+
for name in modules:
102+
mod = __import__(name, {}, {}, 'x')
103+
process_mod(name, mod)
104+
105+
print_css()
106+
107+
if __name__ == '__main__':
108+
main()

0 commit comments

Comments
 (0)