我希望使用Sphinx的autosummary扩展和模板,从docstrings递归生成API文档。我想要为每个模块、类、方法、属性和函数生成单独的页面。但是它根本无法检测到我的模板。事实上,如果我只从_templates/autosummary/
中删除module.rst
文件,它会完全以与之前相同的方式呈现整个文件。我已经严格按照这个SO问题的说明进行操作了。如有兴趣,完整的存储库在GitHub上。
编辑:看起来它确实生成了一个不同的文件,我必须删除docs/_autosummary才能读取新模板。然而,现在它生成了一个带有sparse
头和description
头的文件。它不进入{% if classes %}
和{% if functions %}
指令。
我的目录结构如下:
- sparse
- docs
- conf.py
- index.rst
- modules.rst
- _templates/autosummary/module.rst
以下是迄今为止相关的文件:
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 %}
autosummary_generate = True
的autosummary。 - Hameer Abbasi