Custom templates with autosummary

1,028 views
Skip to first unread message

Craig Watson

unread,
Sep 1, 2014, 7:53:57 PM9/1/14
to sphinx...@googlegroups.com
Hi,

I'm having trouble using custom templates with autosummary. Essentially I want a very slightly modified module.rst template, which will add :toctree: directives in order to generate stub files for all members.

So, I have added a module.rst file to _templates/autosummary; I've added this directory to the templates_path list in conf.py and I added :template: module to my index.rst file.

However, nothing is changed and the documentation is generated as if this file didn't exist. Is there something I'm doing wrong, or something I'm missing? 
Any help would be greatly appreciated!

Below are the relevant code snippets:

In my conf.py :
templates_path = ['doc_templates', 'doc_templates/autosummary']

In index.rst:

.. autosummary::
    :template: module
    :toctree: _autosummary

    personne
    recherche


And finally my module.rst template:


{{ fullname }}
{{ underline }}

.. automodule:: {{ fullname }}

   {% block functions %}
   {% if functions %}
   .. rubric:: Fonctions

   .. autosummary::
      :toctree:
   {% for item in functions %}
      {{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

   {% block classes %}
   {% if classes %}
   .. rubric:: Classes

   .. autosummary::
      :toctree:
   {% for item in classes %}
      {{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

   {% block exceptions %}
   {% if exceptions %}
   .. rubric:: Exceptions

   .. autosummary::
      :toctree:
   {% for item in exceptions %}
      {{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

Takayuki Shimizukawa

unread,
Sep 1, 2014, 9:28:43 PM9/1/14
to sphinx...@googlegroups.com
Hi,

autosummary template feature works fine for me.
This is a small sample for the confirmation.
https://www.dropbox.com/s/19x96y6n58m7xa7/autosummary-sample.zip?dl=0

2014-09-02 8:53 GMT+09:00 Craig Watson <cr...@watsons.ch>:
> Hi,
>
> I'm having trouble using custom templates with autosummary. Essentially I
> want a very slightly modified module.rst template, which will add :toctree:
> directives in order to generate stub files for all members.
>
> So, I have added a module.rst file to _templates/autosummary; I've added
> this directory to the templates_path list in conf.py

autosummary will search it's templates in the 'autosummary' directory
under the each 'templates_path' directories, then you just need to add
'_templates' directory to 'templates_path'.

> and I added :template: module to my index.rst file.

If you want to use another template name, it's necessary.
In this case, 'module.rst' will be used automatically.


> However, nothing is changed and the documentation is generated as if this
> file didn't exist. Is there something I'm doing wrong, or something I'm
> missing?
> Any help would be greatly appreciated!
>
> Below are the relevant code snippets:
>
> In my conf.py :
> templates_path = ['doc_templates', 'doc_templates/autosummary']

If you placed the 'module.rst' to the '_templates/autosummary',
template_path needs to have '_templates'.
Regards,
--
Takayuki SHIMIZUKAWA
http://about.me/shimizukawa
Reply all
Reply to author
Forward
0 new messages