首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >狮身人面像自动摘要为每个类生成两个摘要

狮身人面像自动摘要为每个类生成两个摘要
EN

Stack Overflow用户
提问于 2015-12-11 05:23:24
回答 1查看 1.6K关注 0票数 3

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

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

代码语言:javascript
复制
mrpy
====

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

   mrpy.stats
   <other modules...>

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

代码语言:javascript
复制
{{ 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

代码语言:javascript
复制
{{ 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的标题,但包含类的方法和属性的两个表式摘要。

有人知道怎么摆脱其中一个多余的桌子吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-05 04:16:19

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34216659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档