Skip to content

feat: test mini gallery with autoapi and autosummary #736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/736.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test mini gallery with `autoapi` and `autosummary`
11 changes: 11 additions & 0 deletions doc/source/_templates/autosummary/base.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ name | escape | underline}}

.. currentmodule:: {{ module }}

.. auto{{ objtype }}:: {{ objname }}


.. minigallery::
:add-heading: Examples using {{ objname }}

{{ fullname }}
38 changes: 38 additions & 0 deletions doc/source/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{ objname | escape | underline}}

Check failure on line 1 in doc/source/_templates/autosummary/class.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] doc/source/_templates/autosummary/class.rst#L1

[Vale.Spelling] Did you really mean 'objname'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'objname'?", "location": {"path": "doc/source/_templates/autosummary/class.rst", "range": {"start": {"line": 1, "column": 4}}}, "severity": "ERROR"}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}

{% block methods %}

{% if methods %}
.. rubric:: {{ _('Methods') }}

.. autosummary::
:toctree:
{% for item in methods %}
{% if item != "__init__" %}
{{ name }}.{{ item }}
{% endif %}
{%- endfor %}
{% endif %}
{% endblock %}

{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Attributes') }}

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


.. minigallery::
:add-heading: Examples using {{ objname }}

{{ fullname }}
72 changes: 72 additions & 0 deletions doc/source/_templates/autosummary/module.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.. vale off

{{ fullname | escape | underline}}

.. currentmodule:: {{ fullname }}

{% block attributes %}
{% if attributes %}
.. autosummary::
:toctree:
:caption: Attributes

{% for item in attributes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block functions %}
{% if functions %}
.. autosummary::
:toctree:
:caption: Functions

{% for item in functions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block classes %}
{% if classes %}
.. autosummary::
:toctree:
:caption: Classes

{% for item in classes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block exceptions %}
{% if exceptions %}
.. autosummary::
:toctree:
:caption: Classes

{% for item in exceptions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block modules %}
{% if modules %}
.. autosummary::
:toctree:
:recursive:
:caption: Modules
{% for item in modules %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

.. minigallery::
:add-heading: Examples using {{ objname }}

{{ module }}.{{ objname }}

.. vale on
5 changes: 4 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def extract_example_links(
list
List of example links.
"""
g = Github()
token = os.getenv("GITHUB_TOKEN")
g = Github(token) if token else Github()
repo = g.get_repo(repo_fullname)
contents = repo.get_contents(path_relative_to_root)
if not isinstance(contents, list):
Expand Down Expand Up @@ -275,6 +276,8 @@ def download_and_process_files(example_links: List[str]) -> List[str]:
"download_all_examples": False,
# Modules for which function level galleries are created. In
"image_scrapers": ("pyvista", "matplotlib", "plotly.io._sg_scraper.plotly_sg_scraper"),
"doc_module": ("ansys_sphinx_theme",),
"backreferences_dir": "api/_gallery_backreferences",
"default_thumb_file": str(PYANSYS_LIGHT_SQUARE),
}
pyvista.BUILDING_GALLERY = True
Expand Down
59 changes: 59 additions & 0 deletions doc/source/examples/sphinx-gallery/theme-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright (C) 2021 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# noqa: D205, D400
"""Test mini gallery with the ansys-sphinx-theme."""

###############################################################################
# print a message to the console
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This code plots a simple sphere using PyVista.
from ansys_sphinx_theme.examples.sample_func import func # noqa: E402

print("This is an example of a Sphinx Gallery theme example.")

print(func)

###############################################################################
# print a message to the console
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This is to print the console


from ansys_sphinx_theme.examples import samples # noqa: E402

examples = samples.ExampleClass("mystr", ["apple", "orange"], 3)
print(examples)

#################################################################################
# plot a simple sphere
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This code plots a simple sphere using PyVista.

import pyvista as pv # noqa: E402

pv.set_jupyter_backend("html")

sphere = pv.Sphere()
sphere.plot()

###############################################################################
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,11 @@ Import detail
{% endif %}
{% endif %}



.. minigallery::
:add-heading: Examples using {{ obj.obj["full_name"] }}

{{ obj.obj["full_name"] }}
{# ---------------------- End class details -------------------- #}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,9 @@ Module detail
{% endif %}
{% endif %}

.. minigallery::
:add-heading: Examples using {{ obj.obj["full_name"] }}

{{ obj.obj["full_name"] }}

{# ---------------------- End module detail description -------------------- #}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.. vale off

{{ fullname | escape | underline}}

.. currentmodule:: {{ fullname }}

{% block attributes %}
{% if attributes %}
.. autosummary::
:toctree:
:caption: Attributes

{% for item in attributes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block functions %}
{% if functions %}
.. autosummary::
:toctree:
:caption: Functions

{% for item in functions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block classes %}
{% if classes %}
.. autosummary::
:toctree:
:caption: Classes

{% for item in classes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block exceptions %}
{% if exceptions %}
.. autosummary::
:toctree:
:caption: Classes

{% for item in exceptions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block modules %}
{% if modules %}
.. autosummary::
:toctree:
:recursive:
:caption: Modules
{% for item in modules %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

.. minigallery::
:add-heading: Examples using {{ objname }}

{{ module }}.{{ objname }}

.. vale on
Loading