9

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:
bad_coder
  • 11,289
  • 20
  • 44
  • 72
Ken Carrier
  • 91
  • 1
  • 1
  • 2

1 Answers1

17

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
mzjn
  • 48,958
  • 13
  • 128
  • 248