sphinx构建时不包含源代码

12 投票
2 回答
7132 浏览
提问于 2025-04-18 00:19

我正在尝试使用 Sphinx 1.2.1 来为我的 Python 包编写文档。

我在 rst 文件中定义了一些关于每个模块的描述、用法,并添加了 restructured text 的 autodoc 语法,如下所示。

module
------

.. automodule:: RAT.REPORTER.bemrstcreator
    :members:
    :undoc-members:
    :show-inheritance:

以上的设置让我顺利生成了清晰的 HTML 文档,没有任何问题。它从所有的类及其相关成员中提取文档内容,但在 HTML 中包含了源代码。我该如何告诉 Sphinx 不要链接每个模块的源代码呢?

2 个回答

16

你可以在 config.py 文件里找到下一个配置值,然后把它设置为 false(假)。

html_show_sourcelink = False
10

在conf.py文件中,进行所有与特定文档相关的修改时,去掉sphinx.ext.viewcode这个扩展。

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.viewcode',
    'rst2pdf.pdfbuilder'
]

上面的内容被修改为

extensions = [
    'sphinx.ext.autodoc',
    'rst2pdf.pdfbuilder'
]

撰写回答