Skip to content
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

feat: implement autoapi #761

Merged
merged 19 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ This project uses [towncrier](https://towncrier.readthedocs.io/) to generate the

Refer to the [raw release notes](doc/source/changelog.rst) for more information.

[Published release notes](https://mechanical.docs.pyansys.com/version/stable/changelog.html) can be found in the online documentation.
[Release notes](https://mechanical.docs.pyansys.com/version/stable/changelog.html) can be found in the online documentation.
1 change: 1 addition & 0 deletions doc/changelog.d/761.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: implement autoapi
20 changes: 20 additions & 0 deletions doc/source/_templates/autoapi/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. vale off

API reference
=============

This section describes {{ project_name }} endpoints, their capabilities, and how
to interact with them programmatically. See the API reference for ``ansys-tools-path``
`here <path.html>`_.

.. toctree::
:titlesonly:
:maxdepth: 3

{% for page in pages %}
{% if (page.top_level_object or page.name.split('.') | length == 3) and page.display %}
<span class="nf nf-md-package"></span> {{ page.name }}<{{ page.include_path }}>
{% endif %}
{% endfor %}

.. vale on
226 changes: 226 additions & 0 deletions doc/source/_templates/autoapi/python/class.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
.. vale off

{% if obj.display %}

{# ----------------- Start macros definition for tab item ------------------#}
{% 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 is_own_page %}
:class:`{{ obj.name }}`
========={{ "=" * obj.name | length }}

{% endif %}
{% set visible_children = obj.children|selectattr("display")|list %}
{% set own_page_children = visible_children|selectattr("type", "in", own_page_types)|list %}
{% if is_own_page and own_page_children %}
.. toctree::
:hidden:

{% for child in own_page_children %}
{{ child.include_path }}
{% endfor %}

{% endif %}
.. py:{{ obj.type }}:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}{% if obj.args %}({{ obj.args }}){% 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.docstring|indent(3) }}
{% endif %}
{% set this_page_children = visible_children|rejectattr("type", "in", own_page_types)|list %}
{% set visible_abstract_methods = [] %}
{% set visible_constructor_methods = [] %}
{% set visible_instance_methods = [] %}
{% set visible_special_methods = [] %}
{% set visible_static_methods = [] %}
{% set visible_properties = this_page_children|selectattr("type", "equalto", "property")|list %}
{% set visible_attributes = this_page_children|selectattr("type", "equalto", "attribute")|list %}
{% set all_visible_methods = this_page_children|selectattr("type", "equalto", "method")|list %}
{% if all_visible_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 %}
{% endif %}

{% if this_page_children %}

.. py:currentmodule:: {{ obj.short_name }}
{# ------------------------- Begin tab-set definition ----------------------- #}

Overview
--------

.. 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 %}
{# ---------------------- End class tabset -------------------- #}

{# ---------------------- Begin class details -------------------- #}

Import detail
-------------
{% set split_parts = obj.obj["full_name"].split('.') %}
{% set joined_parts = '.'.join(split_parts[:-1]) %}

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 %}
{% if is_own_page and own_page_children %}
{% set visible_attributes = own_page_children|selectattr("type", "equalto", "attribute")|list %}
{% if visible_attributes %}
Attributes
----------

.. autoapisummary::

{% for attribute in visible_attributes %}
{{ attribute.id }}
{% endfor %}


{% endif %}
{% set visible_exceptions = own_page_children|selectattr("type", "equalto", "exception")|list %}
{% if visible_exceptions %}
Exceptions
----------

.. autoapisummary::

{% for exception in visible_exceptions %}
{{ exception.id }}
{% endfor %}


{% endif %}
{% set visible_classes = own_page_children|selectattr("type", "equalto", "class")|list %}
{% if visible_classes %}
Classes
-------

.. autoapisummary::

{% for klass in visible_classes %}
{{ klass.id }}
{% endfor %}


{% endif %}
{% set visible_methods = own_page_children|selectattr("type", "equalto", "method")|list %}
{% if visible_methods %}
Methods
-------

.. autoapisummary::

{% for method in visible_methods %}
{{ method.id }}
{% endfor %}


{% endif %}
{% endif %}

{# ---------------------- End class details -------------------- #}
{% endif %}

.. vale on
Loading
Loading