gpt4 book ai didi

python - 如何链接到 intersphinx 中的根页面

转载 作者:太空狗 更新时间:2023-10-30 02:26:12 25 4
gpt4 key购买 nike

我启用了sphinx.ext.intersphinx在我的项目中并添加了以下配置:

intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'pyserial': ('https://pythonhosted.org/pyserial/', None),
}

我的 index.rst 中有以下内容:

This project depends on the :ref:`pyserial <pyserial:???>` library.

我希望链接指向 http://pythonhosted.org/pyserial/ , intersphinx_mapping 中的根 URL , 但我不知道是什么 ???应该是。

如果我这样做 :ref:`pyserial`:ref:`pyserial <pyserial>` , 我得到 WARNING: undefined label: pyserial (if the link has no caption the label must precede a section header)

如果我这样做 :ref:`pyserial <>`我得到 WARNING: undefined label: (if the link has no caption the label must precede a section header)

我可以替换 :ref:`pyserial <<a href="http://pythonhosted.org/pyserial/>%60_" rel="noreferrer noopener nofollow">http://pythonhosted.org/pyserial/>`_</a> ,但我真的很想通过 intersphinx 引用该页面,以避免链接断开。

我在 Anaconda 的 Python 3.6.2 上使用 sphinx 1.6.3。我并不过分依赖我试图链接到的库。我怀疑答案不会真正与图书馆联系在一起。

如果有任何问题,对 pyserial 文档的常规引用工作得很好。例如:py:class:`serial.Serial`链接到 https://pythonhosted.org/pyserial/pyserial_api.html#serial.Serial .

最佳答案

您已经满足以下要求。这是最后一项令人沮丧的常见原因。

  1. 配置要使用的项目intersphinx .

  2. 远程文档使用 Sphinx,并且实际上有一个名为 objects.inv 的 list 文件。运行 sphinx-build 时,日志条目应该是这样的:

    loading intersphinx inventory from https://docs.python.org/3/objects.inv...
    loading intersphinx inventory from https://pythonhosted.org/pyserial/objects.inv...
  3. 使用 intersphinx 的 Python 项目的语法如下,就像任何 cross-referencing link 一样:

    :role_name:`title <target>`

    所以在你的情况下:

    :ref:`pyserial <pyserial:reference-label-name>`
  4. 最后,给定页面的 list 中可能不存在一些所需的目标。 This answer shows how to see all intersphinx targets ,使用以下内容:

    python -m sphinx.ext.intersphinx 'https://pythonhosted.org/pyserial/objects.inv'

    出现了所有 API 对象,这就是为什么您可以链接到这些对象,但只出现了有限数量的其他对象:

    std:label
    examples Examples : examples.html#examples
    genindex Index : genindex.html#
    miniterm serial.tools.miniterm : tools.html#miniterm
    modindex Module Index : py-modindex.html#
    search Search Page : search.html#
    urls URL Handlers : url_handlers.html#urls

    缺少任意标签是作者的常见烦恼。

    您也可以check the project's reST source for targets在这种情况下,没有像 .. _my-reference-label:.

  5. 这样的引用标签

要解决此问题,您可以使用任意目标之一:

:ref:`pyserial <pyserial:genindex>`

...或者更好的是向您至少为索引页面提供标签的项目提交拉取请求,等待其接受,然后将其用于 intersphinx 链接。其他作者会很感激。

关于python - 如何链接到 intersphinx 中的根页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45699577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com