你看起来有点混乱。狮身人面像并不是一个真正的语法分析器。您的Python代码必须可以运行,以使Sphinx能够捕获文档字符串。这就是为什么将扩展名文件重命名为“.py”没有帮助。
最近,我一直在与Sphinx和Cython合作,并且希望分享我的经验......下面是完整的详细过程,以便从docstrings中为给定的编译Cython扩展自动生成html文档:
[注:我使用的狮身人面像1.1.3和用Cython 0.17.4]
首先,使用Python的“文档字符串”(所有的限制也多了 - 通过例如,你无法用语言形容一个构造函数。见docstrings规格)在用Cython代码:
cdef class PyLabNode:
"""
This is a LabNode !!!
"""
cdef LabNode* thisptr
cdef PyLabNetwork network
def __cinit__(self):
self.thisptr = new LabNode()
def __dealloc__(self):
if self.thisptr:
del self.thisptr
def SetNetwork(self, PyLabNetwork net):
"""
Set the network !!!
"""
self.network = net
,并重新编译 “yourextension.so”。
然后运行“sphinx-quickstart”并回答问题。当被问及“autodoc”时,请不要忘记说“是”。这将生成“Makefile”,“index.rst”文件和“conf.py”文件。
这最后的“conf.py”已被编辑告诉狮身人面像被找到你的模块:
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../../parent/dir/of/yourextension/'))
的“index.rst”文件已被修改,以及分辨哪个模块可能分析:
$ make html
这是足以让我:
Contents:
.. toctree::
:maxdepth: 2
.. automodule:: yourextension
:members:
:undoc-members:
:show-inheritance:
最后通过做建设的文件(我在“.../_ build/html /”目录下得到了一组html文件)。自从上一个问题被问到后,可能是Sphinx和Cython已经发展了,但我没有处理“签名”问题。没有特定的Cython指令使用,也没有任何修正适用于狮身人面像...
希望这会有所帮助。
编辑:好吧,我想回我的话。我遇到了这个问题,“丹”在使用Epydoc时提到了关于“embedignature”的问题(所以我想这也是Sphinx的一个问题)。激活此编译器指令不发送蟒符合签名反正:
PyLabNode.SetNetwork(self, PyLabNetwork net)
这有2个缺点:对于类的前缀和输入参数的点号。
最后,我能想出发送正确的人的唯一办法是在文档字符串的,像这样的第一行写一个兼容的签名:
def SetNetwork(self, PyLabNetwork net):
"""
SetNetwork(self, net)
Set the net !!!
@param self: Handler to this.
@type self: L{PyLabNode}
@param net: The network this node belongs to.
@type net: L{PyLabNetwork}
"""
self.network = net
希望这可以帮助两个狮身人面像和epydoc的用户...
编辑:关于__cinit__
,我能够与Epidoc
成功生成的文档(不与狮身人面像试试)被描述加倍,像这样:
# For Epydoc only (only used for docstring)
def __init__(self, sim):
"""
__init__(self, sim)
Constructor.
@param sim: The simulator this binding is attached to.
@type sim: L{PyLabSimulatorBase}
"""
# Real Cython init
def __cinit__(self, PyLabSimulatorBase sim):
self.thisptr = new LabNetBinding()
self.sites = []
simulator = sim
关于狮身人面像,PARAM应类文档中进行记录,而不是在构造函数,所以它在生成的文档中看起来不错。 – 2014-10-01 09:30:41