我想使用Sphinx的自动摘要扩展和模板从docstring递归地生成API文档。我想要每个模块、类、方法、属性和函数的单独页面。但它根本没有检测到我的模板。实际上,如果我只是将module.rst文件从_templates/autosummary/中删除,那么整个文件的呈现方式与以前完全相同。我一直跟着这个问题去信。如果你感兴趣,完整的存储库在GitHub上。
编辑:它似乎确实生成了一个不同的文件,为了读取新模板,我不得不删除docs/_auto汇总。但是,现在它生成一个带有sparse头和description头的文件。它不会进入{% if classes %}和{% if functions %}指令。
我的目录结构如下:
以下是到目前为止的相关文件:
index.rst
.. sparse documentation master file, created by
sphinx-quickstart on Fri Dec 29 20:58:03 2017.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to sparse's documentation!
==================================
.. toctree::
:maxdepth: 2
:caption: Contents:
modules
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`modules.rst
API Reference
=============
Modules
-------
.. autosummary::
:toctree: _autosummary
sparse_templates/autosummary/module.rst
{{ fullname | escape | underline }}
Description
-----------
.. automodule:: {{ fullname | escape }}
{% if classes %}
Classes
-------
.. autosummary:
:toctree: _autosummary
{% for class in classes %}
{{ class }}
{% endfor %}
{% endif %}
{% if functions %}
Functions
---------
.. autosummary:
:toctree: _autosummary
{% for function in functions %}
{{ function }}
{% endfor %}
{% endif %}发布于 2020-06-29 11:17:52
从SphinxVersion3.1(2020年6月)中,您可以使用新的:recursive:选项获得sphinx.ext.autosummary,以自动检测包中的每个模块,无论嵌套程度如何,并自动为该模块中的每个属性、类、函数和异常生成文档。
发布于 2018-01-03 17:24:19
最后,我需要以下文件:
modules.rst
API Reference
=============
.. rubric:: Modules
.. autosummary::
:toctree: generated
sparse_templates/autosummary/module.rst
{{ fullname | escape | underline }}
.. rubric:: Description
.. automodule:: {{ fullname }}
.. currentmodule:: {{ fullname }}
{% if classes %}
.. rubric:: Classes
.. autosummary::
:toctree: .
{% for class in classes %}
{{ class }}
{% endfor %}
{% endif %}
{% if functions %}
.. rubric:: Functions
.. autosummary::
:toctree: .
{% for function in functions %}
{{ function }}
{% endfor %}
{% endif %}_templates/autosummary/class.rst
{{ fullname | escape | underline}}
.. currentmodule:: {{ module }}
.. autoclass:: {{ objname }}
{% block methods %}
{% block attributes %}
{% if attributes %}
.. HACK -- the point here is that we don't want this to appear in the output, but the autosummary should still generate the pages.
.. autosummary::
:toctree:
{% for item in all_attributes %}
{%- if not item.startswith('_') %}
{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
{% endblock %}
{% if methods %}
.. HACK -- the point here is that we don't want this to appear in the output, but the autosummary should still generate the pages.
.. autosummary::
:toctree:
{% for item in all_methods %}
{%- if not item.startswith('_') or item in ['__call__'] %}
{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
{% endblock %}_templates/autosummary/base.rst
{{ fullname | escape | underline}}
.. currentmodule:: {{ module }}
.. auto{{ objtype }}:: {{ objname }}我还需要转到sphinx/ext/autosummary/generate.py,并在函数generate_autosummary_docs中设置imported_members=True。
如果您没有像我这样使用numpydoc,您可能需要删除.. HACK指令。
https://stackoverflow.com/questions/48074094
复制相似问题