[英]Sphinx automodule: how to reference classes in same module?
我正在尝试使用 sphinx autodoc扩展,特别是automodule
指令为我正在处理的 django 应用程序自动生成文档。 问题是我想在模块中创建对不同类的内部引用,而不必在项目中的每个类/函数上使用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
我希望能够拥有这样的 sphinx 文档文件:
.. automodule: source_code
我可以为 XXXX-some-reference-to-A-XXXX 使用什么参考? 有没有简单的方法来实现这一点? 在此先感谢您的帮助。
您可以引用这样的类:
class B(object):
"""docs for B with reference to :class:`.A`"""
pass
Sphinx 会聪明地尝试找出您所引用的内容。 如果有多个名为A
类,您可能会收到警告,但它应该在当前模块中选择一个。
不知道我是否理解这个问题,但根据交叉引用 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)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.