Skip to content

Commit

Permalink
Move methods into class pages for docs (#1290)
Browse files Browse the repository at this point in the history
### Summary
Moved all the methods and attributes into class pages to speed up the
building process of the documentation with the new ecosystem sphinx
theme.

This PR continues the work done by @Eric-Arellano in
#1231.

See Qiskit/qiskit#10455 for more information.

---------

Co-authored-by: Eric Arellano <[email protected]>
  • Loading branch information
arnaucasau and Eric-Arellano authored Nov 6, 2023
1 parent 0666228 commit 825ef6e
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 70 deletions.
10 changes: 3 additions & 7 deletions docs/_templates/autosummary/analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

.. rubric:: Attributes

.. autosummary::
:toctree: ../stubs/
{% for item in all_attributes %}
{%- if not item.startswith('_') %}
{{ name }}.{{ item }}
.. autoattribute:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
Expand All @@ -32,16 +30,14 @@

.. rubric:: Methods

.. autosummary::
:toctree: ../stubs/
{% for item in all_methods %}
{%- if not item.startswith('_') or item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{{ name }}.{{ item }}
.. automethod:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% for item in inherited_members %}
{%- if item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{{ name }}.{{ item }}
.. automethod:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}

Expand Down
61 changes: 20 additions & 41 deletions docs/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,37 @@
:no-inherited-members:
:no-special-members:

{% block attributes_summary %}
{% if attributes %}
{% block attributes_summary %}

{# This counter lets us only render the heading if there's at least
one valid entry. #}
{% set count = namespace(value=0) %}
{% set wanted_attributes = [] %}
{% for item in attributes%}
{%- if not item.startswith('_') %}
{% set _ = wanted_attributes.append(item)%}
{%- endif -%}
{%- endfor %}

{% for item in attributes %}
{% if not item.startswith('_') %}
{% set count.value = count.value + 1 %}
{% if count.value == 1 %}
{% if wanted_attributes %}
.. rubric:: Attributes

.. autosummary::
:toctree: ../stubs/
{% endif %}

{{ name }}.{{ item }}
{% endif %}
{% endfor %}
{% for item in wanted_attributes %}
.. autoattribute:: {{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
{% endblock %}

{% block methods_summary %}
{% if methods %}
{% block methods_summary %}

{% set count = namespace(value=0) %}
{% set wanted_methods = [] %}
{% for item in all_methods %}

{%- if not item.startswith('_') or item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{% set count.value = count.value + 1 %}
{% if count.value == 1 %}
.. rubric:: Methods

.. autosummary::
:toctree: ../stubs/
{% endif %}
{{ name }}.{{ item }}
{% set _ = wanted_methods.append(item)%}
{%- endif -%}
{%- endfor %}
{% for item in inherited_members %}
{%- if item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{% set count.value = count.value + 1 %}
{% if count.value == 1 %}
.. rubric:: Methods

.. autosummary::
:toctree: ../stubs/
{% endif %}
{{ name }}.{{ item }}
{%- endif -%}
{% if wanted_methods%}
.. rubric:: Methods
{% for item in wanted_methods %}
.. automethod:: {{ name }}.{{ item }}
{%- endfor %}

{% endif %}
{% endblock %}
{% endblock %}
52 changes: 52 additions & 0 deletions docs/_templates/autosummary/class_no_inherited_members.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{# This is identical to class.rst, except for the filtering of the inherited_members. -#}

{% if referencefile %}
.. include:: {{ referencefile }}
{% endif %}

{{ objname }}
{{ underline }}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
:no-members:
:no-inherited-members:
:no-special-members:

{% block attributes_summary %}

{% set wanted_attributes = [] %}
{% for item in attributes%}
{%- if not item.startswith('_') %}
{% set _ = wanted_attributes.append(item)%}
{%- endif -%}
{%- endfor %}

{% if wanted_attributes%}
.. rubric:: Attributes
{% for item in wanted_attributes %}
.. autoattribute:: {{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block methods_summary %}

{% set wanted_methods = [] %}
{% for item in all_methods %}
{%- if item not in inherited_members %}
{%- if not item.startswith('_') or item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{% set _ = wanted_methods.append(item)%}
{%- endif -%}
{%- endif -%}
{%- endfor %}

{% if wanted_methods %}
.. rubric:: Methods
{% for item in wanted_methods %}
.. automethod:: {{ name }}.{{ item }}
{%- endfor %}

{% endif %}
{% endblock %}
10 changes: 3 additions & 7 deletions docs/_templates/autosummary/drawer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

.. rubric:: Attributes

.. autosummary::
:toctree: ../stubs/
{% for item in all_attributes %}
{%- if not item.startswith('_') %}
{{ name }}.{{ item }}
.. autoattribute:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
Expand All @@ -32,16 +30,14 @@

.. rubric:: Methods

.. autosummary::
:toctree: ../stubs/
{% for item in all_methods %}
{%- if not item.startswith('_') or item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{{ name }}.{{ item }}
.. automethod:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% for item in inherited_members %}
{%- if item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{{ name }}.{{ item }}
.. automethod:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}

Expand Down
10 changes: 3 additions & 7 deletions docs/_templates/autosummary/experiment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

.. rubric:: Attributes

.. autosummary::
:toctree: ../stubs/
{% for item in all_attributes %}
{%- if not item.startswith('_') %}
{{ name }}.{{ item }}
.. autoattribute:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
Expand All @@ -32,16 +30,14 @@

.. rubric:: Methods

.. autosummary::
:toctree: ../stubs/
{% for item in all_methods %}
{%- if not item.startswith('_') or item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{{ name }}.{{ item }}
.. automethod:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% for item in inherited_members %}
{%- if item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{{ name }}.{{ item }}
.. automethod:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}

Expand Down
11 changes: 3 additions & 8 deletions docs/_templates/autosummary/plotter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

.. rubric:: Attributes

.. autosummary::
:toctree: ../stubs/
{% for item in all_attributes %}
{%- if not item.startswith('_') %}
{{ name }}.{{ item }}
.. autoattribute:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
Expand All @@ -32,17 +30,14 @@

.. rubric:: Methods

.. autosummary::
:toctree: ../stubs/

{% for item in all_methods %}
{%- if not item.startswith('_') or item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{{ name }}.{{ item }}
.. automethod:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% for item in inherited_members %}
{%- if item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{{ name }}.{{ item }}
.. automethod:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}

Expand Down

0 comments on commit 825ef6e

Please sign in to comment.