我有一个带有函数(lib.py)的python文件,没有类。每个函数具有以下样式:
def fnc1(a,b,c):
'''
This fonction does something.
:param a: lalala
:type a: str
:param b: hahaha
:type b: int
:param c: hohoho
:type c: int
:rtype: int
'''
print a
d = b + c
return d
我只想用Sphinx记录每个函数(输入和输出)。
在完成sphinx快速启动之后,我用lib.py在conf.py中定义了路径。 但是输出的html文件(欢迎页面)是空的。
如果我把自己写进index.rst:
.. function:: func1(a,b,c)
This fonction does something.
:param a: lalala
:type a: str
:param b: hahaha
:type b: int
:param c: hohoho
:type c: int
:rtype: int
可以,它在html文件中显示输入和输出。 但如何自动完成呢?
通常,我认为,在执行sphinx apidoc-o之后,必须在lib.rst中执行此操作, 但在lib.rst中只有:
lib module
==================
.. automodule:: lib
:members:
:undoc-members:
:show-inheritance:
有人能一步一步地解释我必须做什么吗?
首先,当您运行sphinx quickstart时,请确保选择了autodoc:
然后,在生成的索引中,rst通常添加模块以自动包含所有模块(监视标识)。
之后,sphinx apidoc-o确实为我生成了文档。
我编写了一个使用Sphinx编写嵌入式系统中使用的Python代码的指南,但是该指南的第一步可能对您也很有用:
How to generate sphinx documentation for python code running in an embedded system
[编辑]
下面是一个循序渐进的列表:
创建文档文件夹:
mkdir doc
cd doc
sphinx-quickstart
(确保选择autodoc: y
,Makefile: y
)sys.path.insert(0, os.path.abspath('..'))
编辑index.rst并在目录树中指定模块:
sphinx-apidoc -o . ..
make html
firefox _build/html/index.html
相关问题 更多 >
编程相关推荐