autodoc
扩展,autodata
和 autoattribute
指令允许记录变量和常量。请注意,在模块级别变量或类成员的情况下使用方式不同。Sphinx 可以捕获变量声明中的注释并将其包含在文档中(虽然这些注释不是文档字符串,但它们将呈现在文档中)。让我们看一个最小的工作示例:autodata 和 autoattribute 支持注释选项。
your_module_name.py
:"""This modules documentation."""
ONE_CONSTANT = "A constant value."
"""Turns out the comment is rendered as a docstring if we put it underneath."""
#: Lets try it like this
TWO_CONSTANTS = 2000
class OneClass:
"""Commenting members of a class."""
#: Lets try the third comment like this.
THREE_CONSTANTS = 3000
#: Lets try the forth comment like this.
FOUR_CONSTANTS = 4000
your\_module\_name module
=========================
.. automodule:: your_module_name
:members: ONE_CONSTANT, TWO_CONSTANTS
.. autodata:: ONE_CONSTANT
:annotation: =this annotation
.. autoclass:: OneClass
:members:
:undoc-members:
:show-inheritance:
autodata
或automodule
中,以避免它被包含两次。streaming.py
中使用QOSLevel(Enum)
,并通过streaming.rst
进行文档记录,对吗?(顺便说一句,看起来很不错...)我原本以为你想要使用Sphinx生成HTML?但是github页面只呈现.rst
作为源代码摘录。(请注意,在您的项目中没有1个HTML文件,reStructuredText-Sphinx指令未被处理以生成任何内容,它们只是按原样引用)...您还可以在docstrings中使用双引号以符合PEP8规范。您尝试过在本地运行make html
吗? - bad_coderrst
。根据此处的文档,HTML是通过调用make -f Makefile.sphinx html
来生成的:https://github.com/alexgolec/tda-api/blob/master/CONTRIBUTING.rst。您可以在此处阅读原始源代码:https://raw.githubusercontent.com/alexgolec/tda-api/autodoc-not-showing-enum-documentation/docs/streaming.rst。 - alexgolec