【问题标题】:How to make sphinx.ext.viewcode work while not using automodule如何在不使用自动模块的情况下使 sphinx.ext.viewcode 工作
【发布时间】:2016-04-06 14:27:46
【问题描述】:

你好,

我有一个 python 模块“example_doc”,其中包含“MyObj”,我正在尝试使用 sphinx 进行记录。当我使用 'autodoc' 和 autoclass 指令时:

.. autoclass:: testdoc.example_doc.MyObj

它会生成带有对象描述的正确页面,并且由于我使用的是“viewcode”sphinx 扩展,因此我在旁边获得了指向源代码的链接。

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

.. 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

结果:

【问题讨论】:

  • 我无法重现此内容。使用 .. class:: 时,我也会得到一个 [来源] 链接。
  • 我仍然无法重现该问题。你用的是什么版本的狮身人面像?
  • @mzjn 我编辑了我的帖子以包含 sphinx 版本(来自 conda 包的 1.3.5)

标签: python python-sphinx


【解决方案1】:

我遇到了同样的问题。在视图代码扩展中进行了一些调试以找出使用自动文档和手动声明事物之间的不同之处后,我发现您可以通过在所有类之前单独声明模块来使其工作。

也就是说,不要这样做:

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

我不确定这是错误还是预期行为,但无论哪种方式,明确声明该模块都会使 [source] 链接出现在我面前。

【讨论】:

    猜你喜欢
    • 2014-09-04
    • 2015-04-14
    • 1970-01-01
    • 2017-01-29
    • 2011-08-12
    • 1970-01-01
    • 2013-01-26
    • 2017-12-17
    相关资源
    最近更新 更多