din*_*ino 25 python django documentation python-sphinx
我正在尝试使用sphinx autodoc扩展,特别是automodule指令自动生成我正在处理的django app的文档.问题是我想创建模块内不同类的内部引用,而不必在项目中的每个类/函数上使用autoclass和autofunction.对于像这样的源文件:
# source_code.py
class A:
"""docs for A
"""
pass
class B:
"""docs for B with
:ref:`internal reference to A <XXXX-some-reference-to-A-XXXX>`
"""
pass
Run Code Online (Sandbox Code Playgroud)
我希望能够有一个像这样的sphinx文档文件:
.. automodule: source_code
Run Code Online (Sandbox Code Playgroud)
我可以使用什么参考XXXX-some-reference-to-A-XXXX?有没有一种简单的方法来实现这一目标?在此先感谢您的帮助.
jte*_*ace 47
你可以像这样引用一个类:
class B(object):
"""docs for B with reference to :class:`.A`"""
pass
Run Code Online (Sandbox Code Playgroud)
Sphinx会智能地尝试找出你所引用的内容.如果有多个具有该名称的类A,您可能会收到警告,但它应该在当前模块中选择一个.
neu*_*ino 10
不知道我是否理解了这个问题,但是根据交叉引用Python对象,这对我使用autodoc完美无缺
class FlowDirection(GeneralTable):
'''
Heat Flow Direction
:cvar int id: database primary key
:cvar unicode name: name
'''
def __repr__(self):
return u'<FlowDirection {0} instance at {1}>'.format(
self.name, hex(id(self))).encode('utf-8')
def __unicode__(self):
return self.name
class AirCavityRes(GeneralTable):
'''
Air Cavity :term:`thermal resistance`
:cvar flow_direction: heat flow direction
(see :class:`FlowDirection`)
:cvar int id: database primary key
:cvar int if_fd: database foreign key to :class:`FlowDirection`
:cvar float res: :term:`thermal resistance`
:cvar float thick: thickness
'''
def __repr__(self):
return u'<AirCavityRes {0} instance at {1}>'.format(
self.res, hex(id(self)))
Run Code Online (Sandbox Code Playgroud)