Update __init__.py

This commit is contained in:
2026-01-19 11:34:37 +01:00
parent dab38a1fbf
commit 56629c5490

View File

@@ -1,43 +1,44 @@
import importlib
import os import os
import sys import importlib.util
import glob import glob
import sys
# Get the path of the current directory # 1. Get the current directory of this folder
node_path = os.path.dirname(os.path.realpath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
node_dir = os.path.basename(node_path)
# 2. Find all .py files
file_paths = glob.glob(os.path.join(current_dir, "*.py"))
# Initialize global mappings
NODE_CLASS_MAPPINGS = {} NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {} NODE_DISPLAY_NAME_MAPPINGS = {}
# Scan for all .py files in this folder # 3. Iterate and Load
files = glob.glob(os.path.join(node_path, "*.py")) for file_path in file_paths:
# Get filename without extension (e.g., "parallel_loader")
module_name = os.path.splitext(os.path.basename(file_path))[0]
for file in files: # Skip the init file itself
# Get just the filename without extension
module_name = os.path.basename(file).split(".")[0]
# Skip this __init__.py file to avoid infinite loops
if module_name == "__init__": if module_name == "__init__":
continue continue
try: try:
# Dynamically import the module # Force load the file as a module
module = importlib.import_module(f".{module_name}", package=node_dir) spec = importlib.util.spec_from_file_location(module_name, file_path)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
# Look for NODE_CLASS_MAPPINGS in the module # Merge the nodes if found
if hasattr(module, "NODE_CLASS_MAPPINGS"): if hasattr(module, "NODE_CLASS_MAPPINGS"):
NODE_CLASS_MAPPINGS.update(module.NODE_CLASS_MAPPINGS) NODE_CLASS_MAPPINGS.update(module.NODE_CLASS_MAPPINGS)
# Look for NODE_DISPLAY_NAME_MAPPINGS in the module
if hasattr(module, "NODE_DISPLAY_NAME_MAPPINGS"): if hasattr(module, "NODE_DISPLAY_NAME_MAPPINGS"):
NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS) NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS)
print(f"Loaded module: {module_name}") print(f" -> Loaded: {module_name}")
except Exception as e: except Exception as e:
print(f"Error loading module {module_name}: {e}") print(f"!!! Error loading {module_name}: {e}")
# Export the mappings so ComfyUI sees them # 4. Export to ComfyUI
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"] __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]