Python 如何在不使用automodule的情况下使sphinx.ext.viewcode工作

Python 如何在不使用automodule的情况下使sphinx.ext.viewcode工作,python,python-sphinx,Python,Python Sphinx,你好 我有一个python模块'example_doc',其中有'MyObj',我正试图使用sphinx来记录它。当我使用“autodoc”和autoclass指令时: .. autoclass:: testdoc.example_doc.MyObj 它生成了带有对象描述的正确页面,由于我使用的是“viewcode”sphinx扩展,因此在旁边有一个指向源代码的链接 但是,当我尝试直接使用class指令来重现结果时: .. class:: testdoc.example_doc.MyObj

你好

我有一个python模块'example_doc',其中有'MyObj',我正试图使用sphinx来记录它。当我使用“autodoc”和autoclass指令时:

.. autoclass:: testdoc.example_doc.MyObj
它生成了带有对象描述的正确页面,由于我使用的是“viewcode”sphinx扩展,因此在旁边有一个指向源代码的链接

但是,当我尝试直接使用class指令来重现结果时:

.. class:: testdoc.example_doc.MyObj
我没有找到源代码的链接

编辑: 我正在使用conda的sphinx最新版本,即sphinx 1.3.5和 我的conf.py中只有'sphinx.ext.autodoc'和'sphinx.ext.viewcode'作为扩展名

使用的代码:

Source link
===========

autodoc below

.. autoclass:: testdoc.example_doc.MyObj

class below

.. class:: testdoc.example_doc.MyObj
结果:


我也有同样的问题。在viewcode扩展中进行了一点调试,以找出使用autodoc和手动声明内容之间的区别之后,我发现可以通过在所有类之前单独声明模块来实现

也就是说,不要这样做:

Page title
==========

Introductory text goes here

.. class:: testdoc.example_doc.MyObj

    Bla bla bla, example documentation for the first class

.. class:: testdoc.example_doc.MySecondObj

    Bla bla bla, example documentation for the second class
这样做:

Page title
==========

Introductory text goes here

.. module:: testdoc.example_doc

.. class:: MyObj

    Bla bla bla, example documentation for the first class

.. class:: MySecondObj

    Bla bla bla, example documentation for the second class

我不确定这是否是一个bug或预期行为,但无论哪种方式,明确声明模块都会为我显示
[source]
链接。

我无法重现这一点。使用
时,我也会得到一个[source]链接。。类::
。我仍然无法重现该问题。你使用的是什么版本的斯芬克斯?@mzjn我编辑了我的帖子,加入了斯芬克斯版本(来自conda软件包的1.3.5)