TDengine/test/templates/python/material/function.html.jinja

147 lines
5.9 KiB
Text
Raw Normal View History

2025-03-26 03:05:01 +00:00
{#- Template for Python functions.
2025-04-02 09:42:54 +00:00
This template renders a Python function or method.
Context:
function (griffe.Function): The function to render.
root (bool): Whether this is the root object, injected with `:::` in a Markdown page.
heading_level (int): The HTML heading level to use.
config (dict): The configuration options.
-#}
{% block logs scoped %}
{#- Logging block.
This block can be used to log debug messages, deprecation messages, warnings, etc.
2025-03-26 03:05:01 +00:00
-#}
2025-04-02 09:42:54 +00:00
{{ log.debug("Rendering " + function.path) }}
{% endblock logs %}
{% import "language"|get_template as lang with context %}
{#- Language module providing the `t` translation method. -#}
<div class="doc doc-object doc-function">
{% with obj = function, html_id = function.path %}
{% if root %}
{% set show_full_path = config.show_root_full_path %}
{% set root_members = True %}
{% elif root_members %}
{% set show_full_path = config.show_root_members_full_path or config.show_object_full_path %}
{% set root_members = False %}
{% else %}
{% set show_full_path = config.show_object_full_path %}
{% endif %}
{% set function_name = function.path if show_full_path else function.name %}
{#- Brief or full function name depending on configuration. -#}
{% set symbol_type = "method" if function.parent.is_class else "function" %}
{#- Symbol type: method when parent is a class, function otherwise. -#}
{% if "cases/" in function.relative_filepath|string %}
{# Only generate docstring for methods starting with "test_" or "Test" in the "cases" directory #}
{% if function.name.startswith("test_") or function.name.startswith("Test") %}
{% set should_render = true %}
2025-03-26 03:05:01 +00:00
{% else %}
2025-04-02 09:42:54 +00:00
{% set should_render = false %}
2025-03-26 03:05:01 +00:00
{% endif %}
2025-04-02 09:42:54 +00:00
{% else %}
{# For other directories, generate docstring for all methods #}
{% set should_render = true %}
{% endif %}
{% if should_render %}
2025-03-26 03:05:01 +00:00
{% if not root or config.show_root_heading %}
{% filter heading(
heading_level,
role="function",
id=html_id,
class="doc doc-heading",
2025-03-28 02:12:50 +00:00
toc_label=(('<code class="doc-symbol doc-symbol-toc doc-symbol-' + symbol_type + '"></code>&nbsp;')|safe if config.show_symbol_type_toc else '') +
(
2025-03-28 12:23:17 +00:00
function.docstring.value.split("\n", 1)[0] if "cases/" in function.relative_filepath|string and function.docstring.value else
2025-03-28 02:12:50 +00:00
function.name
),
2025-03-26 03:05:01 +00:00
) %}
2025-04-02 09:42:54 +00:00
2025-03-26 03:05:01 +00:00
{% block heading scoped %}
{#- Heading block.
2025-04-02 09:42:54 +00:00
2025-03-26 03:05:01 +00:00
This block renders the heading for the function.
-#}
{% if config.show_symbol_type_heading %}<code class="doc-symbol doc-symbol-heading doc-symbol-{{ symbol_type }}"></code>{% endif %}
{% if config.separate_signature %}
<span class="doc doc-object-name doc-function-name">{{ config.heading if config.heading and root else function_name }}</span>
{% else %}
{%+ filter highlight(language="python", inline=True) %}
{{ function_name }}{% include "signature"|get_template with context %}
{% endfilter %}
{% endif %}
{% endblock heading %}
2025-04-02 09:42:54 +00:00
2025-03-26 03:05:01 +00:00
{% block labels scoped %}
{#- Labels block.
2025-04-02 09:42:54 +00:00
2025-03-26 03:05:01 +00:00
This block renders the labels for the function.
-#}
{% with labels = function.labels %}
{% include "labels"|get_template with context %}
{% endwith %}
{% endblock labels %}
2025-04-02 09:42:54 +00:00
2025-03-26 03:05:01 +00:00
{% endfilter %}
{% block signature scoped %}
{#- Signature block.
This block renders the signature for the function,
as well as its overloaded signatures if any.
-#}
{% if function.overloads %}
<div class="doc-overloads">
{% for overload in function.overloads %}
{% filter format_signature(overload, config.line_length, annotations=True, crossrefs=config.signature_crossrefs) %}
{{ overload.name }}
{% endfilter %}
{% endfor %}
</div>
{% endif %}
{% if config.separate_signature %}
{% filter format_signature(function, config.line_length, crossrefs=config.signature_crossrefs) %}
{{ function.name }}
{% endfilter %}
{% endif %}
{% endblock signature %}
{% else %}
{% if config.show_root_toc_entry %}
{% filter heading(
heading_level,
role="function",
id=html_id,
2025-03-28 02:12:50 +00:00
toc_label=(('<code class="doc-symbol doc-symbol-toc doc-symbol-' + symbol_type + '"></code>&nbsp;')|safe if config.show_symbol_type_toc else '') +
(
2025-03-28 12:23:17 +00:00
function.docstring.value.split("\n", 1)[0] if "cases/" in function.relative_filepath|string and function.docstring.value else
2025-03-28 02:12:50 +00:00
function.name
),
2025-03-26 03:05:01 +00:00
hidden=True,
) %}
{% endfilter %}
{% endif %}
{% set heading_level = heading_level - 1 %}
{% endif %}
2025-04-02 09:42:54 +00:00
2025-03-26 03:05:01 +00:00
<div class="doc doc-contents {% if root %}first{% endif %}">
{% block contents scoped %}
2025-04-02 09:42:54 +00:00
{# 渲染 docstring #}
2025-03-26 03:05:01 +00:00
{% block docstring scoped %}
{% with docstring_sections = function.docstring.parsed %}
{% include "docstring"|get_template with context %}
{% endwith %}
{% endblock docstring %}
{% endblock contents %}
</div>
2025-04-02 09:42:54 +00:00
{% endif %}
{% endwith %}
</div>