[英]Use module docstrings in Sphinx autodoc
In the Sphinx autodoc generated documentation I want kind of an introduction text for each module.在 Sphinx autodoc 生成的文档中,我想要每个模块的介绍文本。 I my logic this is related to the modules docstring.我的逻辑是这与模块文档字符串有关。 But Sphinx ignores it because it appears nowhere in the generated HTML files.但是 Sphinx 忽略了它,因为它在生成的 HTML 文件中没有出现。
# -*- coding: utf-8 -*-
import mypackage
"""This is the modules docstring.
"""
def bar(bar):
"""
This is the function named bar.
Parameters:
bar (str): Just a parameter.
Returns:
str: Just an 'a'.
"""
mypackage.foo(bar)
return('a')
I am not sure if this is in the concept of Sphinx or if Sphinx want me to realize that another way.我不确定这是否属于 Sphinx 的概念,或者 Sphinx 是否希望我以另一种方式实现这一点。
But the point is I do not want to but documentation in the rst
-files.但关键是我不想在rst
文件中记录文档。 Every documentation content should come from the docstrings in the py
-files themselfs.每个文档内容都应该来自py
文件本身的文档字符串。
Based on @mzjn 's comment.基于@mzjn 的评论。
The module docstring must be the first thing in the module (before import
statements).模块文档字符串必须是模块中的第一件事(在import
语句之前)。 See also: https://stackoverflow.com/a/48682589/407651另请参阅: https://stackoverflow.com/a/48682589/407651
So it must be所以一定是
# -*- coding: utf-8 -*-
"""This is the modules docstring.
"""
import mypackage
def bar(bar):
# ...
´´´
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.