diff options
author | Jason Pellerin <jpellerin@gmail.com> | 2007-06-09 19:08:51 +0000 |
---|---|---|
committer | Jason Pellerin <jpellerin@gmail.com> | 2007-06-09 19:08:51 +0000 |
commit | f861838ad173f06b23446d32449e1282f78dcbdd (patch) | |
tree | 9454e51edb3228145d78c4fa0931554e32de9dd6 /scripts | |
parent | 8fe002b4050d7e508bafe5664987a3b67d0dc036 (diff) | |
download | nose-f861838ad173f06b23446d32449e1282f78dcbdd.tar.gz |
Working on doc writers for plugin guide and api docs
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/mkdocs.py | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/scripts/mkdocs.py b/scripts/mkdocs.py new file mode 100755 index 0000000..8caf054 --- /dev/null +++ b/scripts/mkdocs.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python + +import os +import time +from docutils.core import publish_string, publish_parts +from docutils.readers.standalone import Reader +import inspect +import nose +import textwrap + +def write(filename, content): + print filename + fp = open(filename, 'w') + fp.write(content) + fp.close() + + +def doc_word(node): + print "Unknown ref %s" % node.astext() + node['refuri'] = '_'.join( + map(lambda s: s.lower(), node.astext().split(' '))) + '.html' + del node['refname'] + node.resolved = True + return True +doc_word.priority = 100 + + + +class DocReader(Reader): + unknown_reference_resolvers = (doc_word,) + + +def clean_default(val): + print "clean default %s (%s) %s" % (val, type(val), val.__class__) + if isinstance(val, os._Environ): + return '{...}' + return val + +root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) +doc = os.path.join(root, 'doc') +tpl = open(os.path.join(doc, 'doc.html.tpl'), 'r').read() + +std_info = { + 'version': nose.__version__, + 'date': time.ctime() + } + +# plugins +from nose import plugins +from nose.plugins.base import IPluginInterface + +# writing plugins guide +writing_plugins = publish_parts(plugins.__doc__, reader=DocReader(), + writer_name='html') +writing_plugins.update(std_info) +writing_plugins.update({'title': 'Writing Plugins', + 'menu': 'FIXME -- menu'}) +write(os.path.join(doc, 'writing_plugins.html'), tpl % writing_plugins) + +# interface +itf = publish_parts(textwrap.dedent(IPluginInterface.__doc__), + reader=DocReader(), + writer_name='html') + +# methods +attr = [(a, getattr(IPluginInterface, a)) for a in dir(IPluginInterface)] +methods = [m for m in attr if inspect.ismethod(m[1])] +methods.sort() +print "Documenting methods", [a[0] for a in methods] + +method_html = [] +method_tpl = """ +<div class="method %(extra_class)s"> +<span class="name">%(name)s</span><span class="arg">%(arg)s</span><br /> +%(body)s +</div> +""" + + +m_attrs = ('_new', 'changed', 'deprecated', 'generative', 'chainable') +for m in methods: + name, meth = m + ec = [] + for att in m_attrs: + if hasattr(m, att): + ec.append(att) + # padding evens the lines + mdoc = publish_parts(textwrap.dedent(' ' + meth.__doc__), + writer_name='html') + args, varargs, varkw, defaults = inspect.getargspec(meth) + if defaults: + defaults = map(clean_default, defaults) + mdoc.update({'name': name, + 'extra_class': ' '.join(ec), + 'arg': inspect.formatargspec(args, varargs, varkw, defaults)}) + method_html.append(method_tpl % mdoc) + +itf.update(std_info) +itf.update({'title': 'Plugin Interface', + 'menu': 'FIXME -- menu'}) +itf['body'] += '\n'.join(method_html) +write(os.path.join(doc, 'plugin_interface.html'), tpl % itf) + + +#write(doc, tpl, 'writing_plugins.html', plugins.__doc__) +#write(doc, tpl, 'plugin_interface.html', IPluginInterface + + |