如何使用Sphinx在项目的其他文件中引用类和方法?

时间:2015-12-02 20:40:41

标签: python python-2.7 documentation python-sphinx autodoc

我正在尝试编写链接到我的包的其他部分中的某些类和方法的Sphinx文档字符串,但无法弄清楚如何构建这些链接或让它们显示,因为我需要它们

我有

# b.py

class B(object):

    def func_two():
        # ...

my_package/
    a.py
    b.py

我的包裹在哪里

A.func_one

我希望func_two的Sphinx文档显示为

  

使用B中的func_two来填充内容。

并包含指向Bvalue2 = Mockito.when (classProvider.searchClassProviderEx (anyString())) thenAnswer(new Answer() { Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); Object mock = invocation.getMock(); return "called with arguments: " + args; } }); //Following prints "called with arguments: hello" System.out.println(classProvider.searchClassProviderEx("hello")); 的链接。

我尝试了方法和类的全名的各种组合,但似乎不起作用。我该如何做到这一点?

1 个答案:

答案 0 :(得分:1)

要创建对Python对象的交叉引用,请使用Python域提供的角色(:class::meth:等)。请参阅http://sphinx-doc.org/domains.html#cross-referencing-python-objects

示例:

:py:meth:`mymodule.MyClass.mymethod`

要使链接文本只是目标的最后一部分,请使用~(代字号)前缀。请参阅http://sphinx-doc.org/domains.html#cross-referencing-syntax

示例:

:py:meth:`~mymodule.MyClass.mymethod`