try:
    sphinx.main(['sphinx-build', '-b', 'html', '-d', '_build/doctrees', '.',
        '_build/html'])
except SystemExit:
    with file('doc.rst', 'w') as f:
        for line in rst:
            pass
Make Sphinx generate RST class documentation from pydoc