相关疑难解决方法(0)

Python Sphinx引用长名称

我正在研究我的Python模块的文档(使用Sphinx和reST),我发现当交叉引用其他Python对象(模块,类,函数等)时,完整的对象名称最终会非常长.通常它超过80个字符,我不惜一切代价避免.

这是一个例子:

def exampleFunction():
    '''Here is an example docstring referencing another
    :class:`module1.module2.module3.module4.module5.ReallyLongExampleClassName`

    '''
Run Code Online (Sandbox Code Playgroud)

问题是,在为ReallyLongExampleClassName类创建文档时,我为完整路径名称module1.module2.module3.module4.module5.ReallyLongExampleClassaName生成了它.

我想知道是否有办法解决这个问题?我尝试了以下方法,但没有成功:

1)在模块名称的中间添加换行符.例:

:class:`module1.module2.module3.module4.
module5.ReallyLongExampleClassName`
Run Code Online (Sandbox Code Playgroud)

2)以不同的(但仍然是Python可导入的)方式引用类名.例:

:class:`module1.module2.ReallyLongClassName`
Run Code Online (Sandbox Code Playgroud)

我相信,由于ReallyLongClassName的文档与完整路径名相关联,Sphinx无法将缩短版本与完全命名版本相关联.

任何帮助将不胜感激.


编辑04/05/2012:

根据j13r的答案/建议(见下文),我尝试了以下方法:

:class:`module1.module2.module3.module4.module5\
ReallyLongExampleClassName`
Run Code Online (Sandbox Code Playgroud)

这成功了.让它工作的唯一警告是,第二行之前必须没有空格(在文档字符串中使用它时非常令人沮丧).因此,为了使我的原始示例工作,它看起来像:

def exampleFunction():
    '''Here is an example docstring referencing another
    :class:`module1.module2.module3.module4.module5.\
ReallyLongExampleClassName`

    '''
Run Code Online (Sandbox Code Playgroud)

很好,很丑.如果要在"ReallyLongExampleClassName"之前放置空格以将其缩进到与其上面的行相同的级别,则输出将包含空格,因此Sphinx将尝试引用类似"module1.module2.module3.module4.module5.ReallyLongExampleClassName"的内容. "

我还应该注意到,我尝试了另外两种变体,但是没有用:

    # Note: Trying to put a space before the '\'
    :class:`module1.module2.module3.module4.module5. \
ReallyLongExampleClassName`

    # Note: Trying to leave out the '\'
    :class:`module1.module2.module3.module4.module5.
ReallyLongExampleClassName`
Run Code Online (Sandbox Code Playgroud)

我正在寻找一个不涉及破坏文档字符串格式的解决方案,但我想它会做...我想我实际上更喜欢超过80个字符的行.

感谢j13r的答案!

python documentation restructuredtext python-sphinx

9
推荐指数
2
解决办法
2329
查看次数