From 131682ea50c4e69ca1b56c6b9b5fa8228431bba0 Mon Sep 17 00:00:00 2001 From: AI Lab <129358391+1038lab@users.noreply.github.com> Date: Thu, 1 Jan 2026 19:19:10 -0800 Subject: [PATCH] Add files via upload --- __init__.py | 73 ++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/__init__.py b/__init__.py index ff58bb7..058e68c 100644 --- a/__init__.py +++ b/__init__.py @@ -3,13 +3,16 @@ import sys import os import importlib.util -__version__ = "2.9.6" +__version__ = "3.0.0" -# Add module directory to Python path +# Locate current and node directories current_dir = Path(__file__).parent -if str(current_dir) not in sys.path: - sys.modules[__name__] = sys.modules.get(__name__, type(__name__, (), {})) - sys.path.insert(0, str(current_dir)) +nodes_dir = current_dir / "py" + +# Add both current and nodes directories to sys.path +for path in [current_dir, nodes_dir]: + if str(path) not in sys.path: + sys.path.insert(0, str(path)) # Initialize mappings NODE_CLASS_MAPPINGS = {} @@ -18,38 +21,40 @@ WEB_DIRECTORY = "./web" def load_nodes(): """Automatically discover and load node definitions""" - for file in current_dir.glob("*.py"): - if file.stem == "__init__": + for base in (current_dir, nodes_dir): + if not base.exists(): continue - - try: - # Import module - spec = importlib.util.spec_from_file_location(file.stem, file) - if spec and spec.loader: - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - - # Update mappings - if hasattr(module, "NODE_CLASS_MAPPINGS"): - NODE_CLASS_MAPPINGS.update(module.NODE_CLASS_MAPPINGS) - if hasattr(module, "NODE_DISPLAY_NAME_MAPPINGS"): - NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS) - - # Initialize paths if available - if hasattr(module, "Paths") and hasattr(module.Paths, "LLM_DIR"): - os.makedirs(module.Paths.LLM_DIR, exist_ok=True) - - except Exception as e: - print(f"Error loading {file.name}: {str(e)}") + for file in base.rglob("*.py"): + if file.stem == "__init__": + continue + models_dir = current_dir / "models" + try: + if file.is_relative_to(models_dir): + continue + except Exception: + if str(models_dir) in str(file): + continue + + try: + spec = importlib.util.spec_from_file_location(file.stem, file) + if spec and spec.loader: + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + + if hasattr(module, "NODE_CLASS_MAPPINGS"): + NODE_CLASS_MAPPINGS.update(module.NODE_CLASS_MAPPINGS) + if hasattr(module, "NODE_DISPLAY_NAME_MAPPINGS"): + NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS) + + if hasattr(module, "Paths") and hasattr(module.Paths, "LLM_DIR"): + os.makedirs(module.Paths.LLM_DIR, exist_ok=True) + except Exception as e: + print(f"Error loading {file}: {e}") # Load all nodes load_nodes() -__all__ = [ - "NODE_CLASS_MAPPINGS", - "NODE_DISPLAY_NAME_MAPPINGS" -] -# print(f'\033[34m[ComfyUI-RMBG] v{__version__} \033[92mLoaded\033[0m') - -print(f'\033[34m[ComfyUI-RMBG]\033[0m v\033[93m{__version__}\033[0m | \033[93m{len(NODE_CLASS_MAPPINGS)} nodes\033[0m \033[92mLoaded\033[0m') +__all__ = ["NODE_CLASS_MAPPINGS","NODE_DISPLAY_NAME_MAPPINGS"] +print(f'\033[34m[ComfyUI-RMBG]\033[0m v\033[93m{__version__}\033[0m | ' + f'\033[93m{len(NODE_CLASS_MAPPINGS)} nodes\033[0m \033[92mLoaded\033[0m')