Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 4f184c4553ea7bc3ade5b76af9dc8d6fb623b8df 1 parent 4a679cc
@colinrothwell colinrothwell authored
Showing with 109 additions and 86 deletions.
  1. +1 −0  .gitignore
  2. +108 −86 tools/makedoc.py
View
1  .gitignore
@@ -1 +1,2 @@
*.pyc
+.DS_Store
View
194 tools/makedoc.py 100644 → 100755
@@ -1,86 +1,108 @@
-import sys
-sys.path.insert(0, '..')
-import web
-import inspect
-
-modules = [
- 'web.application',
- 'web.contrib.template',
- 'web.db',
- 'web.debugerror',
- 'web.form',
- 'web.http',
- 'web.httpserver',
- 'web.net',
- 'web.session',
- 'web.template',
- 'web.utils',
- 'web.webapi',
- 'web.webopenid',
- 'web.wsgi'
-]
-
-qstart = '<code class="head">'
-qend = '</code>'
-
-def process_func(name, f):
- print qstart + name + inspect.formatargspec(*inspect.getargspec(f)) + qend + ': '
- print inspect.getdoc(f)
- print
-
-def process_class(name, cls):
- bases = [b.__name__ for b in cls.__bases__]
- if bases:
- name = name + '(' + ",".join(bases) + ')'
-
- print qstart + 'class ' + name + qend + ': '
- print inspect.getdoc(cls)
- print
-
-def process_storage(name, d):
- print qstart + name + qend + ': '
- print d['__doc__']
-
-def process_mod(name, mod):
- print '<a name="%s"></a>' % name
- print '##', name
- print
-
- all = getattr(mod, '__all__', None)
-
- for k, v in inspect.getmembers(mod):
- if k.startswith('_'):
- continue
-
- if inspect.getmodule(v) == mod:
- if inspect.isclass(v):
- process_class(k, v)
- elif inspect.isfunction(v):
- process_func(k, v)
-
- # specical case for generating docs for web.ctx and web.config
- elif all and k in all and isinstance(v, (web.storage, web.threadeddict)) and hasattr(v, '__doc__'):
- process_storage(k, v)
-
-def print_css():
- print
- print '<style type="text/css">'
- print ' #content {margin-left: 20px;}'
- print ' .head {margin-left: -20px;}'
- print ' h2 {margin-left: -20px;}'
- print '</style>'
- print
-
-def main():
- for name in modules:
- print '* <a href="#%s">%s</a>' %(name, name)
- print
-
- for name in modules:
- mod = __import__(name, {}, {}, 'x')
- process_mod(name, mod)
-
- print_css()
-
-if __name__ == '__main__':
- main()
+import sys
+sys.path.insert(0, '..')
+import web
+import inspect
+
+modules = [
+ 'web.application',
+ 'web.contrib.template',
+ 'web.db',
+ 'web.debugerror',
+ 'web.form',
+ 'web.http',
+ 'web.httpserver',
+ 'web.net',
+ 'web.session',
+ 'web.template',
+ 'web.utils',
+ 'web.webapi',
+ 'web.webopenid',
+ 'web.wsgi'
+]
+
+
+qstart = '<code class="head">'
+qend = '</code>'
+
+func_start = '<div style="margin-left:%dpx">'
+func_end = '</div>'
+
+tab_width = 20 #width for tabs in px
+
+def process_func(name, f, tablevel=1):
+ if tablevel != 1: print func_start % (tablevel * tab_width)
+ sys.stdout.write(qstart + name + inspect.formatargspec(*inspect.getargspec(f)) + qend)
+ doc = inspect.getdoc(f)
+ if not doc is None:
+ print ": "
+ print doc
+ print
+ if tablevel != 1: print func_end
+ print
+
+def process_class(name, cls):
+ bases = [b.__name__ for b in cls.__bases__]
+ if bases:
+ name = name + '(' + ",".join(bases) + ')'
+
+ sys.stdout.write(qstart + 'class ' + name + qend)
+ doc = inspect.getdoc(cls)
+ if not doc is None:
+ print ': '
+ print inspect.getdoc(cls)
+ print
+ methods = [(m, getattr(cls, m)) for m in dir(cls)
+ if not m.startswith('_') and inspect.ismethod(getattr(cls, m))]
+ #Possible todo: see if code is faster with the get method in the rendering
+ #loop.
+ for m in methods: process_func(m[0], m[1], 2)
+
+def process_storage(name, d):
+ print qstart + name + qend + ': '
+ print d['__doc__']
+
+def process_mod(name, mod):
+ print '<a name="%s"></a>' % name
+ print '##', name
+ print '<a href="#top">Back to top</a>'
+ print
+
+ all = getattr(mod, '__all__', None)
+
+ for k, v in inspect.getmembers(mod):
+ if k.startswith('_'):
+ continue
+
+ if inspect.getmodule(v) == mod:
+ if inspect.isclass(v):
+ process_class(k, v)
+ elif inspect.isfunction(v):
+ process_func(k, v)
+
+ # specical case for generating docs for web.ctx and web.config
+ elif all and k in all and isinstance(v, (web.storage, web.threadeddict)) and hasattr(v, '__doc__'):
+ process_storage(k, v)
+
+def print_css():
+ print
+ print '<style type="text/css">'
+ print ' #content {margin-left: %dpx;}'% (tab_width)
+ print ' .head {margin-left: -20px;}'
+ print ' h2 {margin-left: -20px;}'
+ print '</style>'
+ print
+
+def main():
+ print '<a name="top"></a>'
+ for name in modules:
+ print '* <a href="#%s">%s</a>' %(name, name)
+ print
+
+ for name in modules:
+ mod = __import__(name, {}, {}, 'x')
+ process_mod(name, mod)
+
+ print_css()
+
+if __name__ == '__main__':
+ main()
Please sign in to comment.
Something went wrong with that request. Please try again.