Skip to content

Commit

Permalink
[experiment] Change autosummary template
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Jul 7, 2023
1 parent 1bf4084 commit 2fe9646
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 65 deletions.
44 changes: 17 additions & 27 deletions example_docs/docs/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{#
The general principle of this is that we manually document attributes here in
the same file, but give all methods their own page. By default, we document
We show all the class's methods and attributes on the same page. By default, we document
all methods, including those defined by parent classes.
-#}

Expand All @@ -9,33 +8,24 @@
.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
{#-
Avoid having autodoc populate the class with the members we're about to
summarize to avoid duplication.
#}
:no-members:
:show-inheritance:
{#
Methods all get their own separate page, with their names and the first lines
of their docstrings tabulated. The documentation from `__init__` is
automatically included in the standard class documentation, so we don't want
to repeat it.
-#}
{% block methods_summary %}{% set wanted_methods = (methods | reject('==', '__init__') | list) %}{% if wanted_methods %}
.. rubric:: Methods

.. autosummary::
:nosignatures:
:toctree: ../stubs/
{% for item in wanted_methods %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}{% endblock %}

{% block attributes_summary %}{% if attributes %}
{% block attributes_summary %}
{% if attributes %}
.. rubric:: Attributes
{# Attributes should all be summarized directly on the same page. -#}
{% for item in attributes %}
{% for item in attributes %}
.. autoattribute:: {{ item }}
{%- endfor %}
{% endif %}{% endblock -%}
{%- endfor %}
{% endif %}
{% endblock -%}

{% block methods_summary %}
{% set wanted_methods = (methods | reject('==', '__init__') | list) %}
{% if wanted_methods %}
.. rubric:: Methods
{% for item in wanted_methods %}
.. automethod:: {{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
{#
This is very similar to the default class template, except this one is used
when we don't want to generate any inherited methods.
-#}
{# This is identical to class.rst, except for the filtering in `set wanted_methods`. -#}

{{ objname | escape | underline }}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
{#-
Avoid having autodoc populate the class with the members we're about to
summarize to avoid duplication.
#}
:no-members:
:show-inheritance:
{#
Methods all get their own separate page, with their names and the first lines
of their docstrings tabulated.
-#}
{% block methods_summary %}{% set wanted_methods = (methods | reject('in', inherited_members) | reject('==', '__init__') | list) %}{% if wanted_methods %}
.. rubric:: Methods Defined Here

.. autosummary::
:nosignatures:
:toctree: ../stubs/
{% for item in wanted_methods %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}{% endblock %}

{% block attributes_summary %}{% if attributes %}
{% block attributes_summary %}
{% if attributes %}
.. rubric:: Attributes
{# Attributes should all be summarized directly on the same page. -#}
{% for item in attributes %}
{% for item in attributes %}
.. autoattribute:: {{ item }}
{%- endfor %}
{% endif %}{% endblock -%}
{%- endfor %}
{% endif %}
{% endblock -%}

{% block methods_summary %}
{% set wanted_methods = (methods | reject('in', inherited_members) | reject('==', '__init__') | list) %}
{% if wanted_methods %}
.. rubric:: Methods
{% for item in wanted_methods %}
.. automethod:: {{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
11 changes: 0 additions & 11 deletions tests/js/qiskit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,6 @@ test.describe("api docs", () => {
await expect(content).toHaveScreenshot();
});

test("method page", async ({ page }) => {
await page.goto("stubs/api_example.Electron.compute_momentum.html");
const content = page.locator("div.article-container");
await expect(content).toHaveScreenshot();

// Also test a method with @typing.overload.
await page.goto("stubs/api_example.Electron.overloaded_func.html");
const content2 = page.locator("div.article-container");
await expect(content2).toHaveScreenshot();
});

test("function page", async ({ page }) => {
await page.goto("stubs/api_example.my_function.html");
const content = page.locator("div.article-container");
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2fe9646

Please sign in to comment.