我使用sphinx.ext.autosummary生成python文档。在conf.py中,autodoc和autosummary的配置如下:
autodoc_member_order = 'bysource'
## Default flags used by autodoc directives
autodoc_default_flags = ['members','undoc-members']
## Generate autodoc stubs with summaries from code
autosummary_generate = True我使用一个模板:
myModuleName
=======
.. autosummary::
:toctree: _autosummary
:template: modules.rst
myModule模块模板为:
{{ fullname }}
{{ underline }}
.. automodule:: {{ fullname }}
{% block functions %}
{% if functions %}
.. rubric:: Functions
.. autosummary::
:toctree: {{ objname }}
{% for item in functions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
{% block classes %}
{% if classes %}
.. rubric:: Classes
.. autosummary::
:toctree: {{ objname }}
:template: class.rst
{% for item in classes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
{% block exceptions %}
{% if exceptions %}
.. rubric:: Exceptions
.. autosummary::
{% for item in exceptions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}类模板为:
{{ fullname }}
{{ underline }}
.. currentmodule:: {{ module }}
.. autoclass:: {{ objname }}
{% block methods %}
{% if methods %}
.. rubric:: Methods
.. autosummary::
:toctree: {{ objname }}
{% for item in methods %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
{% block attributes %}
{% if attributes %}
.. rubric:: Attributes
.. autosummary::
:toctree: {{ objname }}
{% for item in attributes %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}它工作得很好,但它添加了文档中继承的每个方法,而没有'show-inheritance‘标志(它应该添加每个继承的成员)。
有什么想法吗?
发布于 2019-01-11 19:09:01
看起来确实没有任何标志(例如:no-inherited-members:)对此有任何影响,但是你可以修改你的类模板来解决这个问题。
{% for item in methods %}
{%- if item not in inherited_members %}
~{{ name }}.{{ item }}
{%- endif %}
{%- endfor %}上面的内容似乎对我很有帮助。希望这能帮上忙。
https://stackoverflow.com/questions/43983799
复制相似问题