模块中的Sphinx autodoc功能 [英] Sphinx autodoc functions within module
问题描述
我刚开始使用狮身人面像并愿意学习.
I am just getting started with sphinx and willing to learn.
我想将我的各种功能分解为 index.rst
文件中的不同部分.因此,每个函数都有其自己的标头.
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.
例如,如果我有一个名为 test.py
的python文件,并且在该文件中,我有2个函数:
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")
我如何在 index.rst
中将test.py文件中的两个功能分开?
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:
如果我能弄清楚如何分离功能,那么在 index.html
中看起来更干净!现在,如果我仅在下面运行以下命令,则输出不是很干净:
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:
推荐答案
您可以使用 自动功能
.像这样:
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
这篇关于模块中的Sphinx autodoc功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!