From 90b7dbb3f1243472010cfa484c70b89a35791ed4 Mon Sep 17 00:00:00 2001 From: diodiogod Date: Mon, 9 Jun 2025 22:47:33 -0300 Subject: [PATCH 1/2] feat: add user-friendly error message for missing submodule Improve error handling when the submodule is not properly initialized, showing a clear visual message with installation instructions. --- __init__.py | 84 +++++++++++++++++++++++++++++++++++------ test_submodule_check.py | 50 ++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 11 deletions(-) create mode 100644 test_submodule_check.py diff --git a/__init__.py b/__init__.py index d2c880d..29a568e 100644 --- a/__init__.py +++ b/__init__.py @@ -1,15 +1,77 @@ -from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS +import os +import sys +import shutil -__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"] +# Try to import ComfyUI-specific modules, but don't fail if they're not available +try: + import folder_paths + is_comfyui_environment = True +except ImportError: + is_comfyui_environment = False -import shutil -import folder_paths -import os +# Check if the submodule exists +SUBMODULE_PATH = os.path.join(os.path.dirname(__file__), "stable_diffusion_prompt_reader") +if not os.path.exists(SUBMODULE_PATH) or not os.listdir(SUBMODULE_PATH): + # Define colors for better visibility in console + RED = "\033[1;31m" + YELLOW = "\033[1;33m" + BLUE = "\033[1;34m" + RESET = "\033[0m" + + # Create a visually distinct error message + error_message = f""" +{RED}╔══════════════════════════════════════════════════════════════════════════════╗ +║ INSTALLATION ERROR ║ +╚══════════════════════════════════════════════════════════════════════════════╝{RESET} + +{YELLOW}SD Prompt Reader Node{RESET} requires additional files that are missing. + +{BLUE}The Problem:{RESET} +This node uses a git submodule that wasn't properly initialized during installation. + +{BLUE}How to Fix:{RESET} +Run the following commands in your ComfyUI custom_nodes directory: + +{YELLOW}cd comfyui-prompt-reader-node +git submodule init +git submodule update{RESET} + +{BLUE}Current Directory:{RESET} +{YELLOW}{os.path.dirname(os.path.abspath(__file__))}{RESET} + +{BLUE}Alternative Fix:{RESET} +Reinstall using the recursive clone command: + +{YELLOW}git clone --recursive https://github.com/receyuki/comfyui-prompt-reader-node.git{RESET} + +For more information, please visit: +https://github.com/receyuki/comfyui-prompt-reader-node#installation -WEB_DIRECTORY = "./js" +{RED}The node will not function until this is resolved. -# remove old directory -comfy_path = os.path.dirname(folder_paths.__file__) -old_dir = os.path.join(comfy_path, "web", "extensions", "SDPromptReader") -if os.path.exists(old_dir): - shutil.rmtree(old_dir) +╚══════════════════════════════════════════════════════════════════════════════╝{RESET} +""" + + print(error_message) + + # We'll still try to define the required variables to prevent further errors + NODE_CLASS_MAPPINGS = {} + NODE_DISPLAY_NAME_MAPPINGS = {} + + # Exit early - don't try to import from the missing submodule + __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"] +else: + # Normal initialization when submodule exists + from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS + + __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"] + + WEB_DIRECTORY = "./js" + + # Only run ComfyUI-specific code if we're in the ComfyUI environment + if is_comfyui_environment: + # remove old directory + comfy_path = os.path.dirname(folder_paths.__file__) + old_dir = os.path.join(comfy_path, "web", "extensions", "SDPromptReader") + if os.path.exists(old_dir): + shutil.rmtree(old_dir) diff --git a/test_submodule_check.py b/test_submodule_check.py new file mode 100644 index 0000000..6bb5879 --- /dev/null +++ b/test_submodule_check.py @@ -0,0 +1,50 @@ +import os +import sys + +# Check if the submodule exists +SUBMODULE_PATH = os.path.join(os.path.dirname(__file__), "stable_diffusion_prompt_reader") +if not os.path.exists(SUBMODULE_PATH) or not os.listdir(SUBMODULE_PATH): + # Define colors for better visibility in console + RED = "\033[1;31m" + YELLOW = "\033[1;33m" + BLUE = "\033[1;34m" + RESET = "\033[0m" + + # Create a visually distinct error message + error_message = f""" +{RED}╔══════════════════════════════════════════════════════════════════════════════╗ +║ INSTALLATION ERROR ║ +╚══════════════════════════════════════════════════════════════════════════════╝{RESET} + +{YELLOW}SD Prompt Reader Node{RESET} requires additional files that are missing. + +{BLUE}The Problem:{RESET} +This node uses a git submodule that wasn't properly initialized during installation. + +{BLUE}How to Fix:{RESET} +Run the following commands in your ComfyUI custom_nodes directory: + +{YELLOW}cd comfyui-prompt-reader-node +git submodule init +git submodule update{RESET} + +{BLUE}Current Directory:{RESET} +{YELLOW}{os.path.dirname(os.path.abspath(__file__))}{RESET} + +{BLUE}Alternative Fix:{RESET} +Reinstall using the recursive clone command: + +{YELLOW}git clone --recursive https://github.com/receyuki/comfyui-prompt-reader-node.git{RESET} + +For more information, please visit: +https://github.com/receyuki/comfyui-prompt-reader-node#installation + +{RED}The node will not function until this is resolved. + +╚══════════════════════════════════════════════════════════════════════════════╝{RESET} +""" + + print(error_message) + print("Submodule check: Missing") +else: + print("Submodule check: Present") From 17e46aa14ef952ff78dfcf4e3250f7302fb070eb Mon Sep 17 00:00:00 2001 From: diodiogod Date: Tue, 10 Jun 2025 15:57:16 -0300 Subject: [PATCH 2/2] delete test --- test_submodule_check.py | 50 ----------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 test_submodule_check.py diff --git a/test_submodule_check.py b/test_submodule_check.py deleted file mode 100644 index 6bb5879..0000000 --- a/test_submodule_check.py +++ /dev/null @@ -1,50 +0,0 @@ -import os -import sys - -# Check if the submodule exists -SUBMODULE_PATH = os.path.join(os.path.dirname(__file__), "stable_diffusion_prompt_reader") -if not os.path.exists(SUBMODULE_PATH) or not os.listdir(SUBMODULE_PATH): - # Define colors for better visibility in console - RED = "\033[1;31m" - YELLOW = "\033[1;33m" - BLUE = "\033[1;34m" - RESET = "\033[0m" - - # Create a visually distinct error message - error_message = f""" -{RED}╔══════════════════════════════════════════════════════════════════════════════╗ -║ INSTALLATION ERROR ║ -╚══════════════════════════════════════════════════════════════════════════════╝{RESET} - -{YELLOW}SD Prompt Reader Node{RESET} requires additional files that are missing. - -{BLUE}The Problem:{RESET} -This node uses a git submodule that wasn't properly initialized during installation. - -{BLUE}How to Fix:{RESET} -Run the following commands in your ComfyUI custom_nodes directory: - -{YELLOW}cd comfyui-prompt-reader-node -git submodule init -git submodule update{RESET} - -{BLUE}Current Directory:{RESET} -{YELLOW}{os.path.dirname(os.path.abspath(__file__))}{RESET} - -{BLUE}Alternative Fix:{RESET} -Reinstall using the recursive clone command: - -{YELLOW}git clone --recursive https://github.com/receyuki/comfyui-prompt-reader-node.git{RESET} - -For more information, please visit: -https://github.com/receyuki/comfyui-prompt-reader-node#installation - -{RED}The node will not function until this is resolved. - -╚══════════════════════════════════════════════════════════════════════════════╝{RESET} -""" - - print(error_message) - print("Submodule check: Missing") -else: - print("Submodule check: Present")