andrewharp / ComfyUI-EasyNodes

Makes creating new nodes for ComfyUI a breeze.
MIT License
82 stars 11 forks source link

IndexError: list index out of range when initializing after updating comfyui #13

Open trojblue opened 1 week ago

trojblue commented 1 week ago

here: https://github.com/andrewharp/ComfyUI-EasyNodes/blob/a2aeb8bfca654b2c4881975f9fc89d03218a2b8b/easy_nodes/easy_nodes.py#L718

the module_name getting passed into it is comfyui-router, which does not contain any dots, therefore gets a import failed error:

Traceback (most recent call last):
  File "/rmt/yada/apps/comfyui/nodes.py", line 1993, in load_custom_node
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/rmt/yada/apps/comfyui/custom_nodes/comfyui-router/__init__.py", line 34, in <module>
    easy_nodes.initialize_easy_nodes(default_category="ComfyUI Router", auto_register=True)
  File "/root/miniconda3/lib/python3.10/site-packages/easy_nodes/easy_nodes.py", line 122, in initialize_easy_nodes
    _ensure_package_dicts_exist(frame)
  File "/root/miniconda3/lib/python3.10/site-packages/easy_nodes/easy_nodes.py", line 720, in _ensure_package_dicts_exist
    package_name = module_name.split('.')[-2]
IndexError: list index out of range

node folder init code:

# comfyui-router/__init__.py
import easy_nodes
easy_nodes.initialize_easy_nodes(default_category="ComfyUI Router", auto_register=True)

from .comfy_nodes import *  # noqa: F403, E402

NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS = easy_nodes.get_node_mappings()

print("NODE_CLASS_MAPPINGS", NODE_CLASS_MAPPINGS)
print("NODE_DISPLAY_NAME_MAPPINGS", NODE_DISPLAY_NAME_MAPPINGS)

__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]

# Optional: export the node list to a file so that e.g. ComfyUI-Manager can pick it up.
easy_nodes.save_node_list(os.path.join(os.path.dirname(__file__), "node_list.json"))

the code works fine before I updated comfyui from 0.19 to latest (9c5fca75f46f7b9f18c07385925f151a7629a94f). I tried using auto_register=False, which gets imported successfully, but if i add a debug print the frame is still a string with no dots

trojblue commented 1 week ago

update: adding a try-except block seems to fix it?

def _ensure_package_dicts_exist(module_name: str):

    try:
        package_name = module_name.split('.')[-2]
    except IndexError: # package installed with pip install -e .
        package_name = module_name

init code:

import easy_nodes
easy_nodes.initialize_easy_nodes(default_category="ComfyUI Router", auto_register=True)

from .comfy_nodes import *  # noqa: F403, E402

# NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS = easy_nodes.get_node_mappings()

# print("NODE_CLASS_MAPPINGS", NODE_CLASS_MAPPINGS)
# print("NODE_DISPLAY_NAME_MAPPINGS", NODE_DISPLAY_NAME_MAPPINGS)

# __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]

# Optional: export the node list to a file so that e.g. ComfyUI-Manager can pick it up.
# easy_nodes.save_node_list(os.path.join(os.path.dirname(__file__), "node_list.json"))