Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Not a full answer, more or less a starting point: </p> <p><code>autodoc</code> translates auto directives to python directives. So one can use autodoc events to get the translated python directives.</p> <p>For example if you have the following <code>mymodule.py</code>:</p> <pre><code>#!/usr/bin/env python # -*- coding: utf-8 -*- """ This is my module. """ def my_test_func(a, b=1): """This is my test function""" return a + b class MyClass(object): """This is my class""" def __init__(x, y='test'): """The init of my class""" self.x = float(x) self.y = y def my_method(self, z): """This is my method. :param z: a number :type z: float, int :returns: the sum of self.x and z :rtype: float """ return self.x + z </code></pre> <p><code>sphinx-apidoc</code> will create</p> <pre><code>mymodule Module =============== .. automodule:: mymodule :members: :undoc-members: :show-inheritance: </code></pre> <p>The following extension (or addition to <code>conf.py</code>):</p> <pre><code>NAMES = [] DIRECTIVES = {} def get_rst(app, what, name, obj, options, signature, return_annotation): doc_indent = ' ' directive_indent = '' if what in ['method', 'attribute']: doc_indent += ' ' directive_indent += ' ' directive = '%s.. py:%s:: %s' % (directive_indent, what, name) if signature: # modules, attributes, ... don't have a signature directive += signature NAMES.append(name) rst = directive + '\n\n' + doc_indent + obj.__doc__ + '\n' DIRECTIVES[name] = rst def write_new_docs(app, exception): txt = ['My module documentation'] txt.append('-----------------------\n') for name in NAMES: txt.append(DIRECTIVES[name]) print '\n'.join(txt) with open('../doc_new/generated.rst', 'w') as outfile: outfile.write('\n'.join(txt)) def setup(app): app.connect('autodoc-process-signature', get_rst) app.connect('build-finished', write_new_docs) </code></pre> <p>will give you:</p> <pre><code>My module documentation ----------------------- .. py:module:: mymodule This is my module. .. py:class:: mymodule.MyClass(x, y='test') This is my class .. py:method:: mymodule.MyClass.my_method(z) This is my method. :param z: a number :type z: float, int :returns: the sum of self.x and z :rtype: float .. py:function:: mymodule.my_test_func(a, b=1) This is my test function </code></pre> <p>However as <code>autodoc</code> emits no event, when the translation is completed, So further processing done by autodoc has to be adapted to the docstrings here. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload