-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add API templates for sphinx-autoapi (#278)
Co-authored-by: Revathyvenugopal162 <[email protected]> Co-authored-by: Revathy Venugopal <[email protected]> Co-authored-by: Roberto Pastor Muela <[email protected]>
- Loading branch information
1 parent
5f96257
commit f513218
Showing
6 changed files
with
488 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/ansys_sphinx_theme/theme/ansys_sphinx_theme/_templates/autoapi/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
API reference | ||
============= | ||
|
||
This section describes {{ project_name }} endpoints, their capabilities, and how | ||
to interact with them programmatically. | ||
|
||
.. toctree:: | ||
:titlesonly: | ||
:maxdepth: 3 | ||
|
||
{% for page in pages %} | ||
{% if (page.top_level_object or page.name.split('.') | length == 3) and page.display %} | ||
🖿 {{ page.name }}<{{ page.include_path }}> | ||
{% endif %} | ||
{% endfor %} |
191 changes: 191 additions & 0 deletions
191
...ansys_sphinx_theme/theme/ansys_sphinx_theme/_templates/autoapi/python/class.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
{# ------------------------- Begin macros definition ----------------------- #} | ||
|
||
{% macro tab_item_from_objects_list(objects_list, title="") -%} | ||
|
||
.. tab-item:: {{ title }} | ||
|
||
.. list-table:: | ||
:header-rows: 0 | ||
:widths: auto | ||
|
||
{% for obj in objects_list %} | ||
* - :py:attr:`~{{ obj.name }}` | ||
- {{ obj.summary }} | ||
{% endfor %} | ||
{%- endmacro %} | ||
|
||
{# --------------------------- End macros definition ----------------------- #} | ||
|
||
{% if obj.display %} | ||
|
||
{% if render_in_single_page and obj["type"] in render_in_single_page %} | ||
{{ obj.short_name }} | ||
{{"=" * obj.name|length }} | ||
{% endif %} | ||
|
||
.. py:{{ obj["type"] }}:: {{ obj["short_name"] }}{% if obj["args"] %}({{ obj["args"] }}){% endif %} | ||
{% if render_in_single_page and obj["type"] in render_in_single_page %} | ||
:canonical: {{ obj["obj"]["full_name"] }} | ||
{% endif %} | ||
|
||
{% for (args, return_annotation) in obj.overloads %} | ||
{{ " " * (obj.type | length) }} {{ obj.short_name }}{% if args %}({{ args }}){% endif %} | ||
{% endfor %} | ||
|
||
|
||
{% if obj.bases %} | ||
{% if "show-inheritance" in autoapi_options %} | ||
Bases: {% for base in obj.bases %}{{ base|link_objs }}{% if not loop.last %}, {% endif %}{% endfor %} | ||
{% endif %} | ||
|
||
{% if "show-inheritance-diagram" in autoapi_options and obj.bases != ["object"] %} | ||
.. autoapi-inheritance-diagram:: {{ obj.obj["full_name"] }} | ||
:parts: 1 | ||
{% if "private-members" in autoapi_options %} | ||
:private-bases: | ||
{% endif %} | ||
|
||
{% endif %} | ||
{% endif %} | ||
|
||
{% if obj.docstring -%} | ||
{{ obj.summary|indent(3) }} | ||
{% endif %} | ||
|
||
{% if "inherited-members" in autoapi_options %} | ||
{% set visible_classes = obj.classes|selectattr("display")|list %} | ||
{% else %} | ||
{% set visible_classes = obj.classes|rejectattr("inherited")|selectattr("display")|list %} | ||
{% endif %} | ||
|
||
{% for klass in visible_classes %} | ||
{{ klass.render()|indent(3) }} | ||
{% endfor %} | ||
|
||
{% if "inherited-members" in autoapi_options %} | ||
{% set visible_properties = obj.properties|selectattr("display")|list %} | ||
{% else %} | ||
{% set visible_properties = obj.properties|rejectattr("inherited")|selectattr("display")|list %} | ||
{% endif %} | ||
|
||
{% if "inherited-members" in autoapi_options %} | ||
{% set visible_attributes = obj.attributes|selectattr("display")|list %} | ||
{% else %} | ||
{% set visible_attributes = obj.attributes|rejectattr("inherited")|selectattr("display")|list %} | ||
{% endif %} | ||
|
||
{% if "inherited-members" in autoapi_options %} | ||
{% set all_visible_methods = obj.methods|selectattr("display")|list %} | ||
{% else %} | ||
{% set all_visible_methods = obj.methods|rejectattr("inherited")|selectattr("display")|list %} | ||
{% endif %} | ||
|
||
{% set visible_abstract_methods = [] %} | ||
{% set visible_constructor_methods = [] %} | ||
{% set visible_instance_methods = [] %} | ||
{% set visible_special_methods = [] %} | ||
{% set visible_static_methods = [] %} | ||
|
||
{% for element in all_visible_methods %} | ||
{% if "abstractmethod" in element.properties %} | ||
{% set _ = visible_abstract_methods.append(element) %} | ||
|
||
{% elif "staticmethod" in element.properties %} | ||
{% set _ = visible_static_methods.append(element) %} | ||
|
||
{% elif "classmethod" in element.properties or element.name in ["__new__", "__init__"] %} | ||
{% set _ = visible_constructor_methods.append(element) %} | ||
|
||
{% elif element.name.startswith("__") and element.name.endswith("__") and element.name not in ["__new__", "__init__"] %} | ||
{% set _ = visible_special_methods.append(element) %} | ||
|
||
{% else %} | ||
{% set _ = visible_instance_methods.append(element) %} | ||
|
||
{% endif %} | ||
{% endfor %} | ||
|
||
|
||
{% set class_objects = visible_properties + visible_attributes + all_visible_methods %} | ||
|
||
{# ------------------------ Begin tabset definition ----------------------- #} | ||
|
||
{% if class_objects %} | ||
|
||
{% if render_in_single_page and obj["type"] in render_in_single_page %} | ||
Overview | ||
-------- | ||
.. py:currentmodule:: {{ obj.short_name }} | ||
{% endif %} | ||
.. tab-set:: | ||
|
||
{% if visible_abstract_methods %} | ||
{{ tab_item_from_objects_list(visible_abstract_methods, "Abstract methods") }} | ||
{% endif %} | ||
|
||
{% if visible_constructor_methods %} | ||
{{ tab_item_from_objects_list(visible_constructor_methods, "Constructors") }} | ||
{% endif %} | ||
|
||
{% if visible_instance_methods %} | ||
{{ tab_item_from_objects_list(visible_instance_methods, "Methods") }} | ||
{% endif %} | ||
|
||
{% if visible_properties %} | ||
{{ tab_item_from_objects_list(visible_properties, "Properties") }} | ||
{% endif %} | ||
|
||
{% if visible_attributes %} | ||
{{ tab_item_from_objects_list(visible_attributes, "Attributes") }} | ||
{% endif %} | ||
|
||
{% if visible_static_methods %} | ||
{{ tab_item_from_objects_list(visible_static_methods, "Static methods") }} | ||
{% endif %} | ||
|
||
{% if visible_special_methods %} | ||
{{ tab_item_from_objects_list(visible_special_methods, "Special methods") }} | ||
{% endif %} | ||
|
||
{% endif %} | ||
{% endif %} | ||
{# ---------------------- End class tabset -------------------- #} | ||
{# ---------------------- Begin class datails -------------------- #} | ||
|
||
Import detail | ||
------------- | ||
{% set split_parts = obj.obj["full_name"].split('.') %} | ||
{% set joined_parts = '.'.join(split_parts[:-1]) %} | ||
|
||
.. code-block:: python | ||
from {{ joined_parts }} import {{ obj["short_name"] }} | ||
{% if visible_properties %} | ||
|
||
Property detail | ||
--------------- | ||
{% for property in visible_properties %} | ||
{{ property.render() }} | ||
{% endfor %} | ||
{% endif %} | ||
|
||
|
||
{% if visible_attributes %} | ||
Attribute detail | ||
---------------- | ||
{% for attribute in visible_attributes %} | ||
{{ attribute.render() }} | ||
{% endfor %} | ||
{% endif %} | ||
|
||
{% if all_visible_methods %} | ||
Method detail | ||
------------- | ||
{% for method in all_visible_methods %} | ||
{{ method.render() }} | ||
{% endfor %} | ||
{% endif %} | ||
|
||
{# ---------------------- End class details -------------------- #} |
Oops, something went wrong.