Sphinx autodoc functions within module

半腔热情 提交于 2021-02-18 12:42:14

问题


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:

回答1:


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


来源:https://stackoverflow.com/questions/19277385/sphinx-autodoc-functions-within-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!