def to_nodegroup(name=None, singleton=False, type="GeometryNodeTree"):
    """Wrapper for initializing and registering new nodegroups."""

    def registration_fn(fn):
        nonlocal name
        if name is None:
            name = fn.__name__
        if singleton:
            name = name + " (no gc)"

        def init_fn(*args, **kwargs):
            if singleton and name in bpy.data.node_groups:
                return bpy.data.node_groups[name]
            else:
                ng = bpy.data.node_groups.new(name, type)
                nw = NodeWrangler(ng)
                fn(nw, *args, **kwargs)
                return ng

        return init_fn

    return registration_fn
Wrapper for initializing and registering new nodegroups.
infinigen/core/nodes/node_utils.py