Namespace vendored H3 nodes under Dumas

This commit is contained in:
2026-10-20 13:54:56 +00:00
parent 8445f0e500
commit cb9c3f339d
19 changed files with 456 additions and 321 deletions
+74 -9
View File
@@ -10,12 +10,15 @@ from __future__ import annotations
import importlib
import logging
import copy
import dataclasses
import types
_PACKAGES = (
(".vendor.dumas_h3_continuum", "H3 Continuum"),
(".vendor.dumas_minimax_h3_refmod", "MiniMax H3 RefMod"),
(".vendor.dumas_h3_refmod_picker", "H3 RefMod Picker"),
(".vendor.dumas_h3_continuum", "H3 Continuum", "DumasH3Continuum", "Dumas/MiniMax H3/Continuum"),
(".vendor.dumas_minimax_h3_refmod", "MiniMax H3 RefMod", "DumasMiniMaxH3RefMod", "Dumas/MiniMax H3/RefMod"),
(".vendor.dumas_h3_refmod_picker", "H3 RefMod Picker", "DumasH3RefModPicker", "Dumas/MiniMax H3/RefMod Picker"),
)
@@ -29,10 +32,68 @@ def _load_pack(package_name):
return None
def _patch_schema(schema, *, node_id, category, display_name):
"""Return an upstream schema with DUMAS identity and category.
Comfy's modern schema objects have changed from mutable dataclasses to
immutable value objects across API revisions. Support both forms so the
vendored nodes remain usable on the same Comfy versions as their source
packs.
"""
changes = {"node_id": node_id, "category": category, "display_name": display_name}
if dataclasses.is_dataclass(schema):
try:
return dataclasses.replace(schema, **changes)
except (TypeError, ValueError):
pass
patched = copy.copy(schema)
for name, value in changes.items():
try:
setattr(patched, name, value)
except (AttributeError, TypeError):
try:
object.__setattr__(patched, name, value)
except (AttributeError, TypeError):
raise TypeError(
f"Cannot namespace Comfy schema {type(schema).__name__}.{name}"
) from None
return patched
def _namespace_class(node_class, *, node_id, category, display_name):
"""Wrap an upstream class without changing its execution implementation."""
define_schema = getattr(node_class, "define_schema", None)
if define_schema is None:
namespaced = types.new_class(node_class.__name__, (node_class,))
namespaced.CATEGORY = category
namespaced.NODE_CATEGORY = category
else:
def _define_schema(cls):
schema = node_class.define_schema()
return _patch_schema(
schema,
node_id=node_id,
category=category,
display_name=display_name,
)
namespaced = types.new_class(node_class.__name__, (node_class,))
namespaced.define_schema = classmethod(_define_schema)
# Older Comfy builds still inspect these class attributes while
# constructing the node search index.
namespaced.CATEGORY = category
namespaced.NODE_CATEGORY = category
namespaced.__module__ = __name__
namespaced.__qualname__ = node_class.__qualname__
namespaced.__name__ = node_class.__name__
namespaced.__dumas_upstream_id__ = node_id
return namespaced
def _namespaced_mappings():
mappings = {}
display = {}
for relative_name, label in _PACKAGES:
for relative_name, label, prefix, category in _PACKAGES:
package_name = (f"{__package__}{relative_name}" if __package__
else relative_name.lstrip("."))
pack = _load_pack(package_name)
@@ -41,12 +102,16 @@ def _namespaced_mappings():
source_mappings = getattr(pack, "NODE_CLASS_MAPPINGS", {}) or {}
source_display = getattr(pack, "NODE_DISPLAY_NAME_MAPPINGS", {}) or {}
for node_id, node_class in source_mappings.items():
# Keep upstream IDs so the complete upstream web UI and saved
# workflows remain functional. The original packs must not also be
# installed, otherwise ComfyUI will see duplicate node IDs.
mappings[node_id] = node_class
dumas_id = f"{prefix}_{node_id}"
original_name = source_display.get(node_id, node_id)
display[node_id] = f"DUMAS {label} · {original_name}"
dumas_name = f"DUMAS {label} · {original_name}"
mappings[dumas_id] = _namespace_class(
node_class,
node_id=dumas_id,
category=category,
display_name=dumas_name,
)
display[dumas_id] = dumas_name
return mappings, display