When one custom node imports another custom node (e.g., via 'import custom_nodes.other_node'),
the ComfyUI custom node loader would previously load the imported node twice:
1. First time: via the explicit import statement (module name: custom_nodes.other_node)
2. Second time: via the automatic custom node scanner (module name: custom_nodes/other_node)
This caused issues including:
- Module initialization code being executed twice
- Route handlers being registered multiple times
- Potential state inconsistencies and data loss
This fix adds a check before loading a custom node to detect if it's already loaded
in sys.modules under either the standard import name or the path-based name.
If already loaded, it reuses the existing module instead of re-executing it.
Benefits:
- Prevents duplicate initialization of custom nodes
- Allows custom nodes to safely import other custom nodes
- Improves performance by avoiding redundant module loading
- Maintains backward compatibility with existing custom nodes
Also includes linting fix: use lazy % formatting in logging functions.