簡體   English   中英

function 或 class 在 Sphinx 中的 Python 的交叉參考文檔

[英]Cross reference documentation of function or class in Sphinx for Python

我想在解釋性文檔中引用 Python class 的文檔,稍后再引用它的構造函數。 所以想象有一個文件

# MyLib/MyClass.py
class MyClass:
    """Class Introduction"""
    def __init__(paramX):
        """:param paramX: Xes out things"""

和我的第一個文件

#MyLib/docs/source/MyDoc.rst
Some text where :ref:`here` is my reference to "Class Introduction"
 and :ref:`there` follows my reference to the __init__ method documentation

如何讓參考工作:我需要如何以及在 Sphinx 文件中的何處包含 Python 文件以及如何定義(在 Python 文件中)和解析(在第一個文件中)參考? 預期的 output 將是這樣的:

Some text where <link to documentation of class _MyClass_>...
 and 
    'class MyClass
        def __init__(paramX):
           paramX: Xes out things'

如前所述,括號 <..> 包含文檔鏈接,文檔本身出現在“和”之后,在第一個文件中分別由:ref:`here`:ref:`there`

從問題中的示例模塊ref_constructor.py

class MyClass:
    """Class Introduction."""
    def __init__(paramX):
        """The docstring of constructor.

        :param paramX: Xes out things.
        :type paramX: str
        """

使用 reST 文件ref_constructor.rst小心選擇適當的角色,在本例中為:class::meth:

Reference to class constructor
------------------------------

.. automodule:: ref_constructor


.. here begins de documentation.

Some text where :class:`ref_constructor.MyClass` is my reference to "Class Introduction"
and :meth:`ref_constructor.MyClass.__init__` follows my reference to the __init__ method documentation.


Some text where :class:`MyClass` is my reference to "Class Introduction"
and :meth:`MyClass.__init__` follows my reference to the __init__ method documentation.

您可以根據上下文使用完全限定名稱或縮短的 forms 編寫交叉引用

交叉引用 Python 對象

此標記中包含的名稱可以包括模塊名稱和/或 class 名稱。 例如, :py:func:`filter`可以引用當前模塊中名為過濾器的 function 或該名稱的內置 function。 相比之下, :py:func:`foo.filter`顯然是指 foo 模塊中的過濾器 function。

結果

HTML 生成文檔的屏幕截圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM