1. Fix import structure issues: - Remove duplicate py/nodes.py file that conflicts with py/nodes/__init__.py - Add NODE_CLASS_MAPPINGS and NODE_DISPLAY_NAME_MAPPINGS to py/nodes/__init__.py - Fix variable name conflict in BinaryFileSaver (clean_file_name) 2. Add graceful handling for missing dependencies: - Make image utilities optional in utils/__init__.py - Add try-catch blocks for PIL/torch imports in all image-related nodes - Nodes show appropriate error messages when dependencies are missing 3. Fix missing imports: - Add missing PIL.Image import in preview_node.py - Add missing os import in file_node.py - Complete ui_utils.py implementation 4. Ensure ComfyUI compatibility: - All nodes can be imported without crashing - Graceful degradation when torch/PIL not available - Proper error handling and user feedback fix: 修复重构节点中的导入问题和缺失依赖 1. 修复导入结构问题: - 删除与 py/nodes/__init__.py 冲突的重复 py/nodes.py 文件 - 在 py/nodes/__init__.py 中添加 NODE_CLASS_MAPPINGS 和 NODE_DISPLAY_NAME_MAPPINGS - 修复 BinaryFileSaver 中的变量名冲突 (clean_file_name) 2. 为缺失依赖添加优雅处理: - 在 utils/__init__.py 中使图像工具可选 - 在所有图像相关节点中添加 PIL/torch 导入的 try-catch 块 - 当依赖缺失时节点显示适当的错误消息 3. 修复缺失的导入: - 在 preview_node.py 中添加缺失的 PIL.Image 导入 - 在 file_node.py 中添加缺失的 os 导入 - 完成 ui_utils.py 实现 4. 确保 ComfyUI 兼容性: - 所有节点都可以导入而不会崩溃 - 当 torch/PIL 不可用时优雅降级 - 适当的错误处理和用户反馈
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
"""
|
|
DCI Utilities Package
|
|
"""
|
|
|
|
# Import file and UI utilities (no external dependencies)
|
|
from .file_utils import load_binary_data, save_binary_data, get_output_directory, clean_file_name, ensure_directory
|
|
from .ui_utils import format_file_size, format_dci_path, format_image_info, format_binary_info
|
|
|
|
# Try to import image utilities (may fail if torch/PIL not available)
|
|
try:
|
|
from .image_utils import tensor_to_pil, create_checkerboard_background, apply_background, pil_to_comfyui_format
|
|
_image_utils_available = True
|
|
except ImportError as e:
|
|
print(f"Warning: Image utilities not available: {e}")
|
|
_image_utils_available = False
|
|
|
|
# Base utilities always available
|
|
__all__ = [
|
|
# File utilities
|
|
'load_binary_data',
|
|
'save_binary_data',
|
|
'get_output_directory',
|
|
'clean_file_name',
|
|
'ensure_directory',
|
|
|
|
# UI utilities
|
|
'format_file_size',
|
|
'format_dci_path',
|
|
'format_image_info',
|
|
'format_binary_info',
|
|
]
|
|
|
|
# Add image utilities if available
|
|
if _image_utils_available:
|
|
__all__.extend([
|
|
'tensor_to_pil',
|
|
'create_checkerboard_background',
|
|
'apply_background',
|
|
'pil_to_comfyui_format',
|
|
])
|