Attempting to simplify node list definition in a python file via NODES_LIST

This commit is contained in:
kosinkadink1@gmail.com 2025-05-31 15:24:37 -07:00
parent 8b331c5ca2
commit de86d8e32b
3 changed files with 22 additions and 10 deletions

View File

@ -501,6 +501,7 @@ class classproperty(object):
class ComfyNodeV3(ABC): class ComfyNodeV3(ABC):
"""Common base class for all V3 nodes.""" """Common base class for all V3 nodes."""
RELATIVE_PYTHON_MODULE = None
############################################# #############################################
# V1 Backwards Compatibility code # V1 Backwards Compatibility code
#-------------------------------------------- #--------------------------------------------

View File

@ -46,15 +46,15 @@ class V3TestNode(ComfyNodeV3):
NODES: list[ComfyNodeV3] = [ NODES_LIST: list[ComfyNodeV3] = [
V3TestNode, V3TestNode,
] ]
NODE_CLASS_MAPPINGS = {} # NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {} # NODE_DISPLAY_NAME_MAPPINGS = {}
for node in NODES: # for node in NODES_LIST:
schema = node.GET_SCHEMA() # schema = node.GET_SCHEMA()
NODE_CLASS_MAPPINGS[schema.node_id] = node # NODE_CLASS_MAPPINGS[schema.node_id] = node
if schema.display_name: # if schema.display_name:
NODE_DISPLAY_NAME_MAPPINGS[schema.node_id] = schema.display_name # NODE_DISPLAY_NAME_MAPPINGS[schema.node_id] = schema.display_name

View File

@ -26,6 +26,7 @@ import comfy.sd
import comfy.utils import comfy.utils
import comfy.controlnet import comfy.controlnet
from comfy.comfy_types import IO, ComfyNodeABC, InputTypeDict, FileLocator from comfy.comfy_types import IO, ComfyNodeABC, InputTypeDict, FileLocator
from comfy_api.v3.io import ComfyNodeV3
import comfy.clip_vision import comfy.clip_vision
@ -2128,7 +2129,17 @@ def load_custom_node(module_path: str, ignore=set(), module_parent="custom_nodes
if os.path.isdir(web_dir): if os.path.isdir(web_dir):
EXTENSION_WEB_DIRS[module_name] = web_dir EXTENSION_WEB_DIRS[module_name] = web_dir
if hasattr(module, "NODE_CLASS_MAPPINGS") and getattr(module, "NODE_CLASS_MAPPINGS") is not None: if getattr(module, "NODES_LIST", None) is not None:
for node_cls in module.NODES:
node_cls: ComfyNodeV3
schema = node_cls.GET_SCHEMA()
if schema.node_id not in ignore:
NODE_CLASS_MAPPINGS[schema.node_id] = node_cls
node_cls.RELATIVE_PYTHON_MODULE = "{}.{}".format(module_parent, get_module_name(module_path))
if schema.display_name is not None:
NODE_DISPLAY_NAME_MAPPINGS[schema.node_id] = schema.display_name
return True
elif hasattr(module, "NODE_CLASS_MAPPINGS") and getattr(module, "NODE_CLASS_MAPPINGS") is not None:
for name, node_cls in module.NODE_CLASS_MAPPINGS.items(): for name, node_cls in module.NODE_CLASS_MAPPINGS.items():
if name not in ignore: if name not in ignore:
NODE_CLASS_MAPPINGS[name] = node_cls NODE_CLASS_MAPPINGS[name] = node_cls
@ -2137,7 +2148,7 @@ def load_custom_node(module_path: str, ignore=set(), module_parent="custom_nodes
NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS) NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS)
return True return True
else: else:
logging.warning(f"Skip {module_path} module for custom nodes due to the lack of NODE_CLASS_MAPPINGS.") logging.warning(f"Skip {module_path} module for custom nodes due to the lack of NODE_CLASS_MAPPINGS or NODES_LIST (need one).")
return False return False
except Exception as e: except Exception as e:
logging.warning(traceback.format_exc()) logging.warning(traceback.format_exc())