Skip to content

Commit f4a2a82

Browse files
committed
Deduplicate rendered builtin overload docs
* Deduplicate rendered builtin overload docs Signed-off-by: Eric Shi <ershi@nvidia.com> Approved-by: Zach Corse <zcorse@nvidia.com> See merge request omniverse/warp!2382
1 parent bd09b30 commit f4a2a82

1 file changed

Lines changed: 45 additions & 34 deletions

File tree

docs/conf.py

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,50 @@ def normalize_docstring(doc: str) -> str:
299299
return re.sub(r"^(:(rtype|type\s+\w+):.*)\bwp\.", r"\1warp.", rst, flags=re.MULTILINE) if "wp." in rst else rst
300300

301301

302+
def _get_builtin_overloads_info(symbol: str) -> list[dict[str, object]]:
303+
head = wp._src.context.builtin_functions[symbol]
304+
305+
# Collect all overloads, filtering out hidden ones.
306+
# Note: head.overloads already includes the head itself (see Function.__init__)
307+
all_funcs = head.overloads if hasattr(head, "overloads") else [head]
308+
visible_overloads = [f for f in all_funcs if not f.hidden]
309+
310+
overloads_info = []
311+
seen_overloads = set()
312+
for func in visible_overloads:
313+
args = {k: wp._src.context.type_str(v) for k, v in func.input_types.items()}
314+
args_str = ", ".join(f"{k}: {v}" for k, v in args.items())
315+
316+
try:
317+
return_type = wp._src.context.type_str(func.value_func(None, None))
318+
except Exception:
319+
return_type = "None"
320+
321+
if hasattr(func, "overloads"):
322+
sig = wp._src.context.resolve_exported_function_sig(func)
323+
is_exported = sig is not None
324+
else:
325+
is_exported = False
326+
327+
doc = normalize_docstring(func.doc)
328+
overload_key = (args_str, return_type, is_exported, func.is_differentiable, doc)
329+
if overload_key in seen_overloads:
330+
continue
331+
332+
seen_overloads.add(overload_key)
333+
overloads_info.append(
334+
{
335+
"args": args_str,
336+
"return_type": return_type,
337+
"is_exported": is_exported,
338+
"is_differentiable": func.is_differentiable,
339+
"doc": doc,
340+
}
341+
)
342+
343+
return overloads_info
344+
345+
302346
class AutosummaryRenderer(AutosummaryRenderer):
303347
# Module containing Warp's built-ins functions and requiring special handling.
304348
BUILTINS_TEMPLATE_FILE = "builtins.rst"
@@ -308,44 +352,11 @@ def render(self, template_name, context):
308352
fullname = context["fullname"]
309353
symbol = fullname.split(".")[-1]
310354

311-
head = wp._src.context.builtin_functions[symbol]
312-
313-
# Collect all overloads, filtering out hidden ones.
314-
# Note: head.overloads already includes the head itself (see Function.__init__)
315-
all_funcs = head.overloads if hasattr(head, "overloads") else [head]
316-
visible_overloads = [f for f in all_funcs if not f.hidden]
317-
318-
# Build overload info for each visible overload
319-
overloads_info = []
320-
for func in visible_overloads:
321-
args = {k: wp._src.context.type_str(v) for k, v in func.input_types.items()}
322-
323-
try:
324-
return_type = wp._src.context.type_str(func.value_func(None, None))
325-
except Exception:
326-
return_type = "None"
327-
328-
if hasattr(func, "overloads"):
329-
sig = wp._src.context.resolve_exported_function_sig(func)
330-
is_exported = sig is not None
331-
else:
332-
is_exported = False
333-
334-
overloads_info.append(
335-
{
336-
"args": ", ".join(f"{k}: {v}" for k, v in args.items()),
337-
"return_type": return_type,
338-
"is_exported": is_exported,
339-
"is_differentiable": func.is_differentiable,
340-
"doc": normalize_docstring(func.doc),
341-
}
342-
)
343-
344355
# Insert metadata that can be accessed from the template.
345356
context.update(
346357
{
347358
"wp_display_name": f"warp.{symbol}",
348-
"wp_overloads": overloads_info,
359+
"wp_overloads": _get_builtin_overloads_info(symbol),
349360
}
350361
)
351362

0 commit comments

Comments
 (0)