Files
EricRollei-Eric_Image_Proce…/Docs/GRACEFUL_IMPORT_EXPLANATION.md
Eric Rollei d6dd6470cf Add complete Eric Image Processing Nodes implementation
Features:
- 40+ image processing algorithms
- Traditional denoising: Wavelet, NLM, BM3D (GPU-accelerated)
- AI models: DnCNN, SwinIR, SCUNet, NAFNet, Noise-DA
- DeepInv diffusion denoising integration
- Advanced film grain detection and processing
- Frequency domain processing
- Richardson-Lucy deconvolution
- Wiener filter
- External DeepInv service with FastAPI
- Comprehensive documentation and guides
2025-11-06 23:33:19 -08:00

4.0 KiB

Graceful Import Handling in __init__.py

What These Try-Except Blocks Do

The try-except blocks in your __init__.py file implement graceful import handling - they allow your ComfyUI extension to load successfully even when some nodes or dependencies are missing.

Example Block Breakdown:

try:
    from Eric_Image_Processing_Nodes.nodes.adaptive_enhancement_node import AdaptiveEnhancementNode
    ADAPTIVE_AVAILABLE = True
except ImportError as e:
    print(f"Warning: Adaptive enhancement node not available: {e}")
    AdaptiveEnhancementNode = None
    ADAPTIVE_AVAILABLE = False

Step-by-Step Explanation:

1. Try Block - Attempt Import

from Eric_Image_Processing_Nodes.nodes.adaptive_enhancement_node import AdaptiveEnhancementNode
ADAPTIVE_AVAILABLE = True
  • Purpose: Try to import the AdaptiveEnhancementNode class
  • Success: If the import works, set ADAPTIVE_AVAILABLE = True
  • This means: The node file exists, all its dependencies are available, and it can be used

2. Except Block - Handle Import Failure

except ImportError as e:
    print(f"Warning: Adaptive enhancement node not available: {e}")
    AdaptiveEnhancementNode = None
    ADAPTIVE_AVAILABLE = False
  • Purpose: If import fails, handle it gracefully instead of crashing
  • Actions:
    • Print a warning message with the specific error
    • Set AdaptiveEnhancementNode = None (so it exists but is empty)
    • Set ADAPTIVE_AVAILABLE = False (flag to track availability)

Why This Pattern Is Used:

1. Dependency Tolerance

  • Not all users may have all required libraries installed
  • Some nodes might need specific GPU libraries (CUDA, OpenCL)
  • Optional dependencies can be missing without breaking the entire extension

2. Partial Loading

  • If one node fails to import, others can still work
  • Users get only the nodes they can actually use
  • Extension doesn't crash completely due to one missing dependency

3. Development Flexibility

  • During development, you can work on some nodes while others are incomplete
  • Easy to add/remove nodes without breaking the whole system
  • Allows for modular development

How It's Used Later:

1. Conditional Node Registration

ADAPTIVE_MAPPINGS = {}
ADAPTIVE_DISPLAY = {}
if ADAPTIVE_AVAILABLE and AdaptiveEnhancementNode:
    ADAPTIVE_MAPPINGS = {"AdaptiveEnhancementNode": AdaptiveEnhancementNode}
    ADAPTIVE_DISPLAY = {"AdaptiveEnhancementNode": "Adaptive Enhancement"}

2. Safe Node Access

  • Only register nodes that successfully imported
  • Prevents runtime errors when ComfyUI tries to use unavailable nodes
  • Users only see nodes they can actually use

Common Reasons for Import Failures:

  1. Missing Dependencies: Required Python packages not installed
  2. GPU Libraries: CUDA/OpenCL not available on system
  3. File Not Found: Node file doesn't exist or has wrong name
  4. Syntax Errors: Python syntax errors in the node file
  5. Circular Imports: Import dependency loops
  6. Version Conflicts: Incompatible library versions

Benefits of This Approach:

✅ Robustness: Extension works even with missing components ✅ User-Friendly: Clear warnings instead of crashes ✅ Modular: Easy to add/remove features ✅ Development: Safe to work on incomplete features ✅ Deployment: Works across different environments

Alternative Without Graceful Handling:

Without this pattern, a single missing dependency would cause:

ImportError: No module named 'some_required_library'
# Entire extension fails to load
# ComfyUI shows no nodes at all
# User gets confusing error messages

Current Status in Your Code:

Your __init__.py has graceful import handling for:

  • Wavelet denoising nodes
  • Non-local means nodes
  • Richardson-Lucy nodes
  • Wiener filter nodes
  • Frequency enhancement nodes
  • Adaptive enhancement nodes
  • Batch processing nodes
  • Quality assessment nodes
  • Film grain processing nodes
  • All other specialized nodes

This makes your extension very robust and user-friendly!