Sphinx autosummary为每个班级

时间:2015-12-11 05:23:25

标签: python python-sphinx

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

我正在做一个两层摘要,在index.rst我有(最低限度)

mrpy
====

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

   mrpy.stats
   <other modules...>

我可以看到模块级autosummary的自定义模板。我这样做是为了在模块级摘要中,我还得到模块中对象的摘要,每个对象都链接到自己的页面。作为参考,我的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 %}

但是,此类的页面按预期包含标题,类docstring,如预期,但两个列表的方法和属性的摘要。

任何人都知道如何摆脱其中一个冗余表?

1 个答案:

答案 0 :(得分:1)

似乎答案是numpydoc用自体胸腔螺钉固定。将"df$"添加到conf.py可以解决问题。解决方案:https://github.com/phn/pytpm/issues/3#issuecomment-12133978

相关问题