Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sphinx autodoc functions within module

I am just getting started with sphinx and willing to learn.

I would like to break up my various functions into different sections within my index.rst file. So each function has it's own header.

So for example if I have a python file named test.py and within that file I have 2 functions:

def foo():
    """This prints bar"""
    print("bar")

def bar():
    """This prints foo"""
    print("foo")

How could I within the index.rst separate the 2 functions within my test.py file?

:mod:`test` -- foo
.. automodule:: test.foo
   :members:
   :undoc-members:
   :show-inheritance: 
:mod:`test` -- bar
.. automodule:: test.bar
   :members:
   :undoc-members:
   :show-inheritance: 

If I can figure out how to separate the functions so it looks cleaner in the index.html that would be great! As it is now the output is not very clean if I just run the following below:

:mod:`test` -- these are my functions
--------------------------------------------
.. automodule:: test
   :members:
   :undoc-members:
   :show-inheritance:
like image 350
Ken Carrier Avatar asked Oct 09 '13 16:10

Ken Carrier


People also ask

What does Sphinx Autodoc do?

autodoc imports the modules to be documented. If any modules have side effects on import, these will be executed by autodoc when sphinx-build is run. If you document scripts (as opposed to library modules), make sure their main routine is protected by a if __name__ == '__main__' condition.

What is Sphinx-Apidoc?

sphinx-apidoc is a tool for automatic generation of Sphinx sources that, using the autodoc extension, document a whole package in the style of other automatic API documentation tools. MODULE_PATH is the path to a Python package to document, and OUTPUT_PATH is the directory where the generated sources are placed.

What is Conf PY?

The configuration directory must contain a file named conf.py . This file (containing Python code) is called the “build configuration file” and contains (almost) all configuration needed to customize Sphinx input and output behavior. An optional file docutils.


1 Answers

You can use autofunction. Like this:

The test module
===============

The test module contains...

.. currentmodule:: test

The foo function
----------------

.. autofunction:: foo

The bar function
----------------

.. autofunction:: bar
like image 134
mzjn Avatar answered Oct 06 '22 21:10

mzjn