From 56629c5490986644553890443d93bb8d48e5f904 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Mon, 19 Jan 2026 11:34:37 +0100 Subject: [PATCH] Update __init__.py --- __init__.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/__init__.py b/__init__.py index 9f0ded5..4e522c7 100644 --- a/__init__.py +++ b/__init__.py @@ -1,43 +1,44 @@ -import importlib import os -import sys +import importlib.util import glob +import sys -# Get the path of the current directory -node_path = os.path.dirname(os.path.realpath(__file__)) -node_dir = os.path.basename(node_path) +# 1. Get the current directory of this folder +current_dir = os.path.dirname(os.path.abspath(__file__)) + +# 2. Find all .py files +file_paths = glob.glob(os.path.join(current_dir, "*.py")) -# Initialize global mappings NODE_CLASS_MAPPINGS = {} NODE_DISPLAY_NAME_MAPPINGS = {} -# Scan for all .py files in this folder -files = glob.glob(os.path.join(node_path, "*.py")) - -for file in files: - # Get just the filename without extension - module_name = os.path.basename(file).split(".")[0] +# 3. Iterate and Load +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] - # Skip this __init__.py file to avoid infinite loops + # Skip the init file itself if module_name == "__init__": continue try: - # Dynamically import the module - module = importlib.import_module(f".{module_name}", package=node_dir) + # Force load the file as a module + 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"): NODE_CLASS_MAPPINGS.update(module.NODE_CLASS_MAPPINGS) - - # Look for NODE_DISPLAY_NAME_MAPPINGS in the module + if hasattr(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: - 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"] \ No newline at end of file