我有一个带函数(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-quickstart之后,我用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:
autodoc: automatically insert docstrings from modules (y/N) [n]: y
然后,通常在生成的index.rst中添加模块以自动包括所有模块(手表标识)。
.. toctree::
:maxdepth: 4
modules
在此之后,sphinx-apidoc -o会为我生成文档。
我写了一个指南,将Sphinx用于嵌入式系统中使用的Python代码,但是该指南的第一步可能对您也很有用:
如何为嵌入式系统中运行的python代码生成sphinx文档
[编辑]
以下是分步列表:
创建文档文件夹: mkdir doc
├── doc/
└── lib.py
cd doc
sphinx-quickstart
(请确保选择autodoc: y
,Makefile: y
)sys.path.insert(0, os.path.abspath('..'))
编辑index.rst并在toctree中指定模块:
.. toctree::
:maxdepth: 2
modules
sphinx-apidoc -o . ..
make html
firefox _build/html/index.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句