Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid inherited members using autosummary and custom templates?

I generate a python documentation using sphinx.ext.autosummary. The autodoc and autosummary is configured as follow in conf.py :

autodoc_member_order = 'bysource'
## Default flags used by autodoc directives
autodoc_default_flags = ['members','undoc-members']
## Generate autodoc stubs with summaries from code
autosummary_generate = True

I use a template :

myModuleName
=======

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

   myModule

Modules template is :

{{ 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 %}

And class template is :

{{ 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 %}

It works fine but this adds every method inherited in the documentation while the flag 'show-inheritance' (which is supposed to add every inherited member) is absent.

Any ideas?

like image 364
A.Vignon Avatar asked May 15 '17 15:05

A.Vignon


1 Answers

it seems indeed that none of the flags (e.g. :no-inherited-members:) have any effect on this, but you could just modify your class template to solve the problem.

{% for item in methods %}
{%- if item not in inherited_members %}
    ~{{ name }}.{{ item }}
{%- endif %}
{%- endfor %}

the above seems to do the trick for me. hope it helps...

like image 126
eilander17 Avatar answered Nov 11 '22 12:11

eilander17