如何在 Sphinx 中添加指向源代码的链接

Rya*_*an 6 python-sphinx

在此处输入图片说明

class torch.FloatStorage[source]
    byte()
        Casts this storage to byte type
    char()
        Casts this storage to char type
Run Code Online (Sandbox Code Playgroud)

我正在尝试完成一些文档,我设法获得了如上所示的格式,但我不确定如何提供该函数末尾的源代码链接!该链接将人带到包含代码的文件,但我不知道该怎么做,

Pie*_*uyl 11

这要归功于内置的 sphinx 扩展之一。

您正在寻找的那个spinx.ext.viewcode。要启用它,请将字符串添加'sphinx.ext.viewcode'到文件中的列表extensionsconf.py

总之,你应该看到类似的东西 conf.py

extensions = [
    # other extensions that you might already use
    # ...
    'sphinx.ext.viewcode',
]
Run Code Online (Sandbox Code Playgroud)