Files
alessandroperilli-OCS_Nodes/__init__.py
2025-07-06 12:06:07 +01:00

36 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""OCS Nodes package – auto‑loads every *.py in the *nodes* sub‑package
and aggregates their NODE_CLASS_MAPPINGS / NODE_DISPLAY_NAME_MAPPINGS.
"""
from importlib import import_module, reload
from pkgutil import iter_modules
from pathlib import Path
import sys
NODE_CLASS_MAPPINGS: dict[str, type] = {}
NODE_DISPLAY_NAME_MAPPINGS: dict[str, str] = {}
_pkg_dir = Path(__file__).parent / "nodes"
def _merge(child):
NODE_CLASS_MAPPINGS.update(getattr(child, "NODE_CLASS_MAPPINGS", {}))
NODE_DISPLAY_NAME_MAPPINGS.update(getattr(child, "NODE_DISPLAY_NAME_MAPPINGS", {}))
def _load_all():
for info in iter_modules([_pkg_dir.as_posix()]):
if info.name.startswith("_"):
continue
child = import_module(f"{__name__}.nodes.{info.name}")
_merge(child)
_load_all()
# -------- optional hot‑reload hook --------
def refresh():
"""Reload all node modules. Hook this up to ComfyUI's Ctrl+R."""
for name in list(sys.modules):
if name.startswith(f"{__name__}.nodes."):
reload(sys.modules[name])
NODE_CLASS_MAPPINGS.clear()
NODE_DISPLAY_NAME_MAPPINGS.clear()
_load_all()