def generate_layers_doc()

in src/kernels/doc.py [0:0]


def generate_layers_doc(kernel_module: ModuleType, kernel_name: str) -> None:
    # Check if layers module is available
    layers_module = getattr(kernel_module, "layers", None)
    if layers_module is None:
        return

    print("\n## Layers")

    # Track if we found any classes
    found_classes = False

    for class_name, cls in inspect.getmembers(layers_module, inspect.isclass):
        # Exclude classes that were imported.
        if cls.__module__ != layers_module.__name__:
            continue

        found_classes = True

        try:
            # Get docstring, but not from superclasses.
            class_docstring = _get_docstring(cls, use_dict_check=True)
        except Exception:
            print(
                f"Warning: Could not retrieve documentation for class {class_name} in {layers_module.__name__}",
                file=sys.stderr,
            )
            continue

        print(f"\n### Class `{class_name}`")

        # Always print class description (helper handles conversion and formatting)
        class_docstring_mdx = convert_rst_docstring_to_mdx(
            class_docstring, page_info={"package_name": kernel_name}
        )
        description = _extract_description_before_tags(class_docstring_mdx)
        print(f"\n{description}")

        # Document methods
        print("\n#### Methods")

        for method_name, method in inspect.getmembers(cls, inspect.isfunction):
            # Note: also skip __init__, since extension layers cannot have a constructor.
            if method_name.startswith("_"):
                continue

            # Skip methods from superclasses.
            if method_name not in cls.__dict__:
                continue

            try:
                sig = inspect.signature(method)
                method_docstring = _get_docstring(method)
            except ValueError:
                print(
                    f"Warning: Could not retrieve signature for {method_name} in {class_name}",
                    file=sys.stderr,
                )
                continue

            print(f"\n##### Method `{method_name}`")
            print(f"\n`{sig}`")

            _process_and_print_docstring(
                method_docstring,
                kernel_name=kernel_name,
                context_name=method_name,
                header_level=6,
            )

    if not found_classes:
        print("\nNo layers defined.")