From 3a3bac458323edf35d11d45b9c66f21dd48dea14 Mon Sep 17 00:00:00 2001 From: Mencken Davidson <76002183+menckend@users.noreply.github.com> Date: Sun, 6 Oct 2024 10:20:55 -0400 Subject: [PATCH] more autoapi tweaks --- docs/_static/css/custom.css | 15 +++++++++++ docs/_templates/autoapi/macros.rst | 40 ++++++++++++++++++++++++++---- docs/conf.py | 10 ++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 docs/_static/css/custom.css diff --git a/docs/_static/css/custom.css b/docs/_static/css/custom.css new file mode 100644 index 0000000..889b915 --- /dev/null +++ b/docs/_static/css/custom.css @@ -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%; +} diff --git a/docs/_templates/autoapi/macros.rst b/docs/_templates/autoapi/macros.rst index a766e0d..ed52ab5 100644 --- a/docs/_templates/autoapi/macros.rst +++ b/docs/_templates/autoapi/macros.rst @@ -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 %} \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index f9a5a08..0962c34 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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" @@ -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