sphinx: 在 python 中记录数据而不显示数据

sphinx: document data in python without displaying the data

我知道我可以 document (module) constants in sphinx

#: a tuple of primes
primes = (2, 3, 5, 7, 11, 13, 17)

primes =  (2, 3, 5, 7, 11, 13, 17)
"""a tuple of primes"""

随后将出现在 sphinx 生成的文档中;即它看起来像这样:

somemodule.primes

= (2, 3, 5, 7, 11, 13, 17)

a tuple of primes

但是如果数据是一个很长的列表呢?然后我希望能够在文档中有一个文档字符串,但在文档中没有实际数据本身。

这是我希望文档中包含的内容:

somemodule.primes

a tuple of primes

有什么方法可以实现吗?


完整性:

i 运行 sphinx-quickstart 并启用了 autodoc:

autodoc: automatically insert docstrings from modules (y/n) [n]: y

我唯一添加到 index.rst 的是:

``somemodule``
**************

.. automodule:: somemodule
    :members:

somemodule.py 包含这个:

#: a tuple of primes
primes = (2, 3, 5, 7, 11, 13, 17)

然后我在 conf.py 中调整了 sys.path,这样 somemodule.py 就在那个路径中。

我最终在 somemodule.py 中没有 somemodule.primes 的任何文档(这让 sphinx 忽略了它)并将手动文档放入 index.rst

``somemodule``
**************

.. automodule:: somemodule
    :members:

.. py:data:: somemodule.primes

    a tuple of primes

到目前为止,我发现没有办法直接在 somemodule.py 中做类似的事情。

以防万一有人来到这里。要隐藏变量的内容,请使用 .

Example:

primes = (2, 3, 5, 7, 11, 13, 17)
"""A tuple of primes.

   :meta hide-value:
"""