- Add Pydantic parameter validation (src/validation.py) - Add structured logging with structlog fallback - Add IS_CHANGED, OUTPUT_NODE, DESCRIPTION metadata to all nodes - Add comprehensive smoke and unit tests - Fix invert_mask double-application bug - Fix create_fallback_processor()() double call - Resolve merge conflicts in .gitignore, grabcut_nodes.py, nodes.py, requirements.txt - Remove FLOYO_INTEGRATION_GUIDE.md, schemas.py (superseded) - Update CI: Python 3.10-3.12, pytest smoke tests
70 lines
3.0 KiB
Python
70 lines
3.0 KiB
Python
# Check for optional dependencies and provide helpful warnings
|
||
try:
|
||
import sklearn # noqa: F401
|
||
SKLEARN_AVAILABLE = True
|
||
except ImportError:
|
||
SKLEARN_AVAILABLE = False
|
||
print("\n" + "="*70)
|
||
print("⚠️ TransparencyBackgroundRemover: scikit-learn not installed!")
|
||
print("="*70)
|
||
print("The node will work with reduced accuracy (color clustering disabled).")
|
||
print("\nTo install dependencies for best results, run ONE of:")
|
||
print(" • Windows (ComfyUI App): install.bat")
|
||
print(" • Linux/Mac: ./install.sh")
|
||
print(" • Manual: pip install scikit-learn")
|
||
print("\nInstallation files are in: custom_nodes/ComfyUI-TransparencyBackgroundRemover/")
|
||
print("="*70 + "\n")
|
||
|
||
# Import main transparency background remover nodes.
|
||
# Try relative import first (ComfyUI load path); fall back to absolute so
|
||
# the module also works when loaded outside a package context (e.g. pytest
|
||
# discovering files under a repo dir whose hyphenated name isn't a valid
|
||
# Python identifier).
|
||
try:
|
||
from .nodes import NODE_CLASS_MAPPINGS as NODES_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as NODES_DISPLAY_MAPPINGS
|
||
except ImportError:
|
||
from nodes import NODE_CLASS_MAPPINGS as NODES_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as NODES_DISPLAY_MAPPINGS
|
||
|
||
# Import standalone RemoveBackgroundAndResizeNode
|
||
try:
|
||
from .RemoveBackgroundAndResizeNode import (
|
||
NODE_CLASS_MAPPINGS as REMBG_MAPPINGS,
|
||
NODE_DISPLAY_NAME_MAPPINGS as REMBG_DISPLAY_MAPPINGS,
|
||
)
|
||
REMBG_AVAILABLE = True
|
||
except ImportError as e:
|
||
REMBG_MAPPINGS = {}
|
||
REMBG_DISPLAY_MAPPINGS = {}
|
||
REMBG_AVAILABLE = False
|
||
print("\n" + "="*70)
|
||
print("ℹ️ RemoveBackgroundAndResizeNode unavailable:", str(e))
|
||
print("="*70 + "\n")
|
||
|
||
# Try to import GrabCut nodes (optional - requires ultralytics)
|
||
try:
|
||
try:
|
||
from .grabcut_nodes import NODE_CLASS_MAPPINGS as GRABCUT_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as GRABCUT_DISPLAY_MAPPINGS
|
||
except ImportError:
|
||
from grabcut_nodes import NODE_CLASS_MAPPINGS as GRABCUT_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as GRABCUT_DISPLAY_MAPPINGS
|
||
GRABCUT_AVAILABLE = True
|
||
except ImportError as e:
|
||
# GrabCut nodes require additional dependencies (ultralytics, etc.)
|
||
GRABCUT_MAPPINGS = {}
|
||
GRABCUT_DISPLAY_MAPPINGS = {}
|
||
GRABCUT_AVAILABLE = False
|
||
print("\n" + "="*70)
|
||
print("ℹ️ TransparencyBackgroundRemover: GrabCut nodes disabled")
|
||
print("="*70)
|
||
print(f"Reason: {str(e)}")
|
||
print("\nGrabCut nodes require additional dependencies. To enable them:")
|
||
print(" • Install: pip install ultralytics")
|
||
print(" • Or run: pip install -r requirements.txt")
|
||
print("\nMain background remover nodes are still available!")
|
||
print("="*70 + "\n")
|
||
|
||
# Combine node mappings from all modules
|
||
NODE_CLASS_MAPPINGS = {**NODES_MAPPINGS, **GRABCUT_MAPPINGS, **REMBG_MAPPINGS}
|
||
NODE_DISPLAY_NAME_MAPPINGS = {**NODES_DISPLAY_MAPPINGS, **GRABCUT_DISPLAY_MAPPINGS, **REMBG_DISPLAY_MAPPINGS}
|
||
|
||
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
|