refactor(init): simplify initialization process
This commit is contained in:
+28
-43
@@ -3,40 +3,24 @@ PromptManager: A ComfyUI custom node that extends the standard text encoder
|
||||
with persistent prompt storage and advanced search capabilities using SQLite.
|
||||
"""
|
||||
|
||||
# Import logging system
|
||||
try:
|
||||
from .utils.logging_config import get_logger
|
||||
init_logger = get_logger('prompt_manager.init')
|
||||
init_logger.info("Starting to load PromptManager custom node...")
|
||||
except ImportError:
|
||||
# Fallback to print if logging isn't available yet
|
||||
init_logger = None
|
||||
print("[PromptManager] Starting to load PromptManager custom node...")
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
def log_message(message, level='info'):
|
||||
"""Helper to log messages with fallback to print."""
|
||||
if init_logger:
|
||||
getattr(init_logger, level)(message.replace("[PromptManager] ", ""))
|
||||
else:
|
||||
print(f"[PromptManager] {message}")
|
||||
def get_version():
|
||||
"""Parse version from pyproject.toml"""
|
||||
try:
|
||||
pyproject_path = Path(__file__).parent / "pyproject.toml"
|
||||
if pyproject_path.exists():
|
||||
content = pyproject_path.read_text()
|
||||
match = re.search(r'version\s*=\s*["\']([^"\']+)["\']', content)
|
||||
if match:
|
||||
return match.group(1)
|
||||
except Exception:
|
||||
pass
|
||||
return "unknown"
|
||||
|
||||
try:
|
||||
from .prompt_manager import PromptManager
|
||||
log_message("Successfully imported PromptManager class")
|
||||
except Exception as e:
|
||||
log_message(f"ERROR: Failed to import PromptManager class: {e}", 'error')
|
||||
import traceback
|
||||
log_message(f"Traceback: {traceback.format_exc()}", 'error')
|
||||
raise
|
||||
|
||||
try:
|
||||
from .prompt_manager_text import PromptManagerText
|
||||
log_message("Successfully imported PromptManagerText class")
|
||||
except Exception as e:
|
||||
log_message(f"ERROR: Failed to import PromptManagerText class: {e}", 'error')
|
||||
import traceback
|
||||
log_message(f"Traceback: {traceback.format_exc()}", 'error')
|
||||
raise
|
||||
from .prompt_manager import PromptManager
|
||||
from .prompt_manager_text import PromptManagerText
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"PromptManager": PromptManager,
|
||||
@@ -48,9 +32,6 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"PromptManagerText": "Prompt Manager Text",
|
||||
}
|
||||
|
||||
log_message(f"NODE_CLASS_MAPPINGS: {NODE_CLASS_MAPPINGS}")
|
||||
log_message(f"NODE_DISPLAY_NAME_MAPPINGS: {NODE_DISPLAY_NAME_MAPPINGS}")
|
||||
|
||||
# Define path to web directory for UI components
|
||||
WEB_DIRECTORY = "web"
|
||||
|
||||
@@ -69,15 +50,19 @@ try:
|
||||
api = PromptManagerAPI()
|
||||
api.add_routes(routes)
|
||||
|
||||
log_message("API routes registered successfully")
|
||||
log_message(f"Server instance: {config.server_instance}")
|
||||
log_message(f"Routes object: {routes}")
|
||||
|
||||
except Exception as e:
|
||||
log_message(f"Failed to register API routes: {e}", 'error')
|
||||
import traceback
|
||||
log_message(f"Traceback: {traceback.format_exc()}", 'error')
|
||||
# Log to internal logging system without console spam
|
||||
try:
|
||||
from .utils.logging_config import get_logger
|
||||
logger = get_logger('prompt_manager.init')
|
||||
logger.error(f"Failed to register API routes: {e}")
|
||||
except:
|
||||
pass
|
||||
|
||||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
|
||||
|
||||
log_message("[SUCCESS] PromptManager custom node loaded successfully!")
|
||||
# Print startup message with loaded tools
|
||||
print(f"\033[94m[ComfyUI-PromptManager] Version:\033[0m {get_version()}")
|
||||
for node_key, display_name in NODE_DISPLAY_NAME_MAPPINGS.items():
|
||||
print(f"🫶 \033[94mLoaded:\033[0m {display_name}")
|
||||
print(f"\033[94mTotal: {len(NODE_CLASS_MAPPINGS)} tools loaded\033[0m")
|
||||
Reference in New Issue
Block a user