3

我正在使用 Sphinx+autodoc+autosummary 为我的项目 ( mrpy) 生成文档。

我正在做一个两层总结,其中index.rst我有(最少)

mrpy
====

.. autosummary::
   :toctree: _autosummary
   :template: modules.rst

   mrpy.stats
   <other modules...>

如您所见,我为模块级自动摘要使用了自定义模板。我这样做是为了在模块级摘要上,我还获得模块内对象的摘要,每个对象都链接到自己的页面。作为参考,我的modules.rst文件是

{{ 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 %}

mrpy.stats仅包含三个类,当点击索引页面上生成的表格中的链接时,它们得到了很好的总结。当点击这些类之一的链接时,我使用了另一个自定义模板class.rst

{{ 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 %}

但是,该类的页面包含标题,如预期的那样,类文档字符串,如预期的那样,但是该类的方法和属性的两个列表摘要。

任何人都知道如何摆脱冗余表之一?

4

1 回答 1

3

似乎答案是 numpydoc 使用自动摘要来解决问题。添加numpydoc_show_class_members=False到 conf.py 解决了这个问题。解决方案在这里找到:https ://github.com/phn/pytpm/issues/3#issuecomment-12133978

于 2016-01-05T04:16:19.727 回答