【问题标题】:Cross reference target path for :func: :class: only paths from root work:func: :class 的交叉引用目标路径:仅来自根目录的路径
【发布时间】:2023-03-14 00:12:01
【问题描述】:

我有点困惑,为什么我的交叉引用目标无法正常工作。只有完整路径似乎有效。我有以下项目结构:

my_project
-my_project
 -adapters
  -adapter_base
  -adapter_1
  -adapter_2
-docs
 -build
 -source
 -config.py

config.py

sys.path.insert(0, os.path.abspath('..'))

index.rst

.. toctree::
   :maxdepth: 2

   modules/the_api

modules.rst

Adapter Base
------------
.. automodule:: my_project.adapters.base
   :members:
   :inherited-members:
   :show-inheritance:

Adapter 1
---------
.. automodule:: my_project.adapters.adapter_1
   :members:
   :inherited-members:
   :show-inheritance:

adapter_1.py

class Adapter1(object):
   pass

class Adapter1API(object):
   def method_a(self):
        """the docs for this method_b"""
        pass

    def method_b(self):
        """the docs for this method

        This works :func:`my_project.adapters.adapter_1.method_a`
        No link :func:`method_a`
        No link :func:`.method_a`
        No link :func:`.adapter_1.method_a`
        """

正如您在 method_b 中看到的,我尝试了 4 种方法来创建指向 method_a 的目标路径,并且只有完整路径有效。任何想法为什么其他 3 个不是?

【问题讨论】:

    标签: python python-sphinx cross-reference


    【解决方案1】:

    虽然很尴尬,但解决方案是 :meth: 而不是 :func: 不知何故我错过了 sphinx 有一个 :meth: 指令的事实......

    【讨论】:

      猜你喜欢
      • 2011-04-13
      • 2017-05-17
      • 2016-01-12
      • 1970-01-01
      • 2019-03-07
      • 2015-02-02
      • 2015-08-22
      • 2012-07-21
      • 1970-01-01
      相关资源
      最近更新 更多