Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
more autoapi tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
menckend committed Oct 6, 2024
1 parent 69faf3c commit 3a3bac4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
15 changes: 15 additions & 0 deletions docs/_static/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
span.summarylabel {
background-color: var(--color-foreground-secondary);
color: var(--color-background-secondary);
font-size: 70%;
padding-left: 2px;
padding-right: 2px;
border-radius: 3px;
vertical-align: 15%;
padding-bottom: 2px;
filter: opacity(40%);
}

table.summarytable {
width: 100%;
}
40 changes: 35 additions & 5 deletions docs/_templates/autoapi/macros.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
{% macro auto_summary(objs, title='') -%}
{% macro _render_item_name(obj, sig=False) -%}
:py:obj:`{{ obj.name }} <{{ obj.id }}>`
{%- if sig -%}
\ (
{%- for arg in obj.obj.args -%}
{%- if arg[0] %}{{ arg[0]|replace('*', '\*') }}{% endif -%}{{ arg[1] -}}
{%- if not loop.last %}, {% endif -%}
{%- endfor -%}
){%- endif -%}
{%- endmacro %}

{% macro _item(obj, sig=False, label='') %}
* - {{ _render_item_name(obj, sig) }}
- {% if label %}:summarylabel:`{{ label }}` {% endif %}{% if obj.summary %}{{ obj.summary }}{% else %}\-{% endif +%}
{% endmacro %}

{% macro auto_summary(objs, title='') -%}
.. list-table:: {{ title }}
:header-rows: 0
:widths: auto
:class: summarytable

{% for obj in objs -%}
{%- set sig = (obj.type in ['method', 'function'] and not 'property' in obj.properties) -%}

{%- if 'property' in obj.properties -%}
{%- set label = 'prop' -%}
{%- elif 'classmethod' in obj.properties -%}
{%- set label = 'class' -%}
{%- elif 'abstractmethod' in obj.properties -%}
{%- set label = 'abc' -%}
{%- elif 'staticmethod' in obj.properties -%}
{%- set label = 'static' -%}
{%- else -%}
{%- set label = '' -%}
{%- endif -%}

{{- _item(obj, sig=sig, label=label) -}}
{%- endfor -%}

{% for obj in objs %}
* - obj.name
- obj.summary
{% endfor %}
{% endmacro %}
10 changes: 10 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
autoapi_template_dir = "_templates/autoapi"
autodoc_typehints = "signature"

html_css_files = [
"css/custom.css",
]


on_rtd = os.environ.get("READTHEDOCS", None) == "True"
Expand Down Expand Up @@ -84,3 +87,10 @@
napoleon_type_aliases = None
napoleon_attr_annotations = True

def contains(seq, item):
return item in seq

def prepare_jinja_env(jinja_env) -> None:
jinja_env.tests["contains"] = contains

autoapi_prepare_jinja_env = prepare_jinja_env

0 comments on commit 3a3bac4

Please sign in to comment.