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: add API templates #278

Merged
merged 60 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
bfba652
feat: improve autosummary templates
jorgepiloto Aug 16, 2023
209a281
feat: add function to retrieve templates location
jorgepiloto Aug 18, 2023
8111aa8
dbg: working tabs
jorgepiloto Aug 18, 2023
c6cc1ac
dbg: working dynamic tabs
jorgepiloto Aug 18, 2023
d1942a2
dbg: add interfaces tab
jorgepiloto Aug 18, 2023
6d72af7
dbg: add exceptions tab
jorgepiloto Aug 18, 2023
b4edf13
feat: working tree view
jorgepiloto Aug 19, 2023
e9dc27b
feat: working templates with tabs and icons
jorgepiloto Aug 19, 2023
9cb20ad
feat: add enums tab
jorgepiloto Aug 21, 2023
95a184f
feat: add visible classes in toc
jorgepiloto Aug 22, 2023
6cbb2ae
feat: add class rst files
Revathyvenugopal162 Aug 23, 2023
51d1aaa
feat: modify the class.rst
Revathyvenugopal162 Aug 23, 2023
b51be2b
feat: add tabs for all attributes
Revathyvenugopal162 Aug 23, 2023
81ca37d
feat: pre-commit fixed
Revathyvenugopal162 Aug 23, 2023
223307f
feat: use summary insted of description
jorgepiloto Aug 23, 2023
27c79a9
fix: the docstring with numpy
Revathyvenugopal162 Aug 23, 2023
0145ba3
Merge branch 'feat/api-templates' of https://github.com/ansys/ansys-s…
Revathyvenugopal162 Aug 23, 2023
ebc8c26
feat: add current module
Revathyvenugopal162 Aug 23, 2023
05dd038
feat: add lines
Revathyvenugopal162 Aug 23, 2023
40b1a5c
feat: render interfaces and enums
jorgepiloto Aug 24, 2023
3d5d255
feat: add sectioon headings
Revathyvenugopal162 Aug 24, 2023
03963f2
Merge branch 'feat/api-templates' of https://github.com/ansys/ansys-s…
Revathyvenugopal162 Aug 24, 2023
9b4bac1
feat: add docstring only having summary
Revathyvenugopal162 Aug 24, 2023
ff4ff89
feat: differntiate methods
Revathyvenugopal162 Aug 24, 2023
de9afeb
feat: add differnt methods
Revathyvenugopal162 Aug 24, 2023
4276b55
feat: add import detail
Revathyvenugopal162 Aug 24, 2023
4f3026d
feat: attept to chnage the property
Revathyvenugopal162 Aug 24, 2023
70f293e
feat: test cases
Revathyvenugopal162 Aug 25, 2023
5091829
feat: add macros
Revathyvenugopal162 Aug 25, 2023
fc5bd63
Merge branch 'main' into feat/api-templates
Revathyvenugopal162 Aug 28, 2023
bfd963f
Merge branch 'main' into feat/api-templates
Revathyvenugopal162 Aug 28, 2023
2e4a804
feat: add macros for modules
Revathyvenugopal162 Aug 29, 2023
1486621
Merge branch 'main' into feat/api-templates
RobPasMue Aug 31, 2023
a86142e
Merge branch 'main' into feat/api-templates
Revathyvenugopal162 Aug 31, 2023
dcfdc86
fix: style checks
Revathyvenugopal162 Aug 31, 2023
1d5f746
include only in toctree if option is there
Revathyvenugopal162 Sep 5, 2023
f5c1ed9
Merge branch 'main' into feat/api-templates
Revathyvenugopal162 Sep 5, 2023
c507894
fix: Add the toctree class conditions
Revathyvenugopal162 Sep 5, 2023
cd530dd
fix: Add the toctree macros
Revathyvenugopal162 Sep 5, 2023
ffa9ed6
fix: Add the macros for toctree
Revathyvenugopal162 Sep 5, 2023
5d3b7cb
feat: move macros.rst to autoapi/python/
jorgepiloto Sep 6, 2023
84f2fe1
fix: indentation and heading depth
jorgepiloto Sep 6, 2023
90629c5
feat: declare macros at the top
jorgepiloto Sep 6, 2023
890bc8e
fix: remove unused macros.rst
jorgepiloto Sep 6, 2023
590d65a
feat: ensure non single attrs are rendered in the same page
jorgepiloto Sep 7, 2023
5940c6e
fix: ensure objects render in module page
jorgepiloto Sep 7, 2023
62ebacd
feat: map objects in toctree
jorgepiloto Sep 7, 2023
ff015bb
feat: improve rendering of obj in same page
jorgepiloto Sep 7, 2023
f206db1
fix: include module detail only if required
jorgepiloto Sep 7, 2023
4042f19
fix: restore autosummary templates
jorgepiloto Sep 7, 2023
dab5372
doc: restore code link
jorgepiloto Sep 7, 2023
5a78779
fix: links from tables
jorgepiloto Sep 7, 2023
5aff191
feat: allow classes to render in the same apge
jorgepiloto Sep 7, 2023
acddf43
fix: add the obj type
Revathyvenugopal162 Sep 7, 2023
8776fa1
fix: add the obj type in module.rst
Revathyvenugopal162 Sep 7, 2023
3207091
fix: add cononical for module.rst
Revathyvenugopal162 Sep 7, 2023
69cce3e
fix: add the comments
Revathyvenugopal162 Sep 7, 2023
79c96fc
fix: the conditions
Revathyvenugopal162 Sep 8, 2023
f20d949
fix: add conditions for render objects
Revathyvenugopal162 Sep 8, 2023
198056d
fix: add the visible objects without single page render
Revathyvenugopal162 Sep 8, 2023
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ repos:
hooks:
- id: blacken-docs
additional_dependencies: [black==23.7.0]
exclude: 'src/ansys_sphinx_theme/theme/ansys_sphinx_theme/_templates/'
23 changes: 22 additions & 1 deletion src/ansys_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This is the ansys-sphinx-theme module."""
import logging
import os
import pathlib
from typing import Any, Dict

Expand All @@ -21,6 +22,7 @@
JS_PATH = STATIC_PATH / "js"
CSS_PATH = STYLE_PATH / "ansys_sphinx_theme.css"
TEMPLATES_PATH = THEME_PATH / "_templates"
AUTOAPI_TEMPLATES_PATH = TEMPLATES_PATH / "autoapi"
JS_FILE = JS_PATH / "table.js"

# make logo paths available
Expand Down Expand Up @@ -66,6 +68,25 @@ def get_version_match(semver: str) -> str:
return ".".join([major, minor])


def get_autoapi_templates_dir_relative_path(path: pathlib.Path) -> str:
"""Return a string representing the relative path for autoapi templates.

Parameters
----------
path : pathlib.Path
Path to the desired file.

Returns
-------
str
A string rerpesenting the relative path to the autoapi templates.

"""
return os.path.relpath(
str(AUTOAPI_TEMPLATES_PATH.absolute()), start=str(path.parent.absolute())
)


def convert_version_to_pymeilisearch(semver: str) -> str:
"""Convert a semantic version number to pymeilisearch-compatible format.

Expand Down Expand Up @@ -187,7 +208,7 @@ def fix_edit_link_page(link: str) -> str:
logging.debug(f"An error occurred: {e}") # Log the exception as debug info
return link

elif "autoapi" in pagename:
elif pagename in ["autoapi", "api"]:
for obj_node in list(doctree.findall(addnodes.desc)):
domain = obj_node.get("domain")
if domain != "py":
Expand Down
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 %}
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 -------------------- #}
Loading
Loading