【问题标题】:Need a different module name when using Python's Sphinx automodule directive使用 Python 的 Sphinx 自动模块指令时需要不同的模块名称
【发布时间】:2017-11-13 20:47:51
【问题描述】:

我的文件布局如下:

/my_module
    __init__.py
    submodule1.py
    submodule2.py

我使用 Sphinx 的 automodule 指令,例如:

.. automodule:: my_module.submodule1

它生成的文档说我的命令名称类似于:my_module.submodule1.my_function。但是我的__init__submodule1 拉入my_module 命名空间。所以我真正想要的是文档改为my_module.my_function。省略submodule1,因为这不是用户将要使用的。

有没有办法做到这一点?

【问题讨论】:

标签: python python-sphinx


【解决方案1】:

不完全是,但你可以接近。 standard cross-referencing syntax 中有 ~(波浪号)。

如果您在内容前加上~,则链接文本将只是目标的最后一个组成部分。例如,

:py:meth:`~Queue.Queue.get`

将引用Queue.Queue.get,但仅显示get 作为链接文本。这不适用于所有交叉引用角色,但特定于域。

您也许可以使用替换或原始指令,但这会绕过使用autodoc 及其指令的优势。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-09
    • 2022-01-03
    • 1970-01-01
    相关资源
    最近更新 更多