Skip to content

Commit

Permalink
feat: load additional nodes by adding path instead of DIY (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaoses-Ib committed Jan 30, 2024
1 parent b7e5d23 commit 5aaf6ee
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,4 @@ Screenshot:
![](docs/images/README/select.png)

## Additional nodes
See [nodes](nodes/README.md) for the addtional nodes installed with ComfyScript.
See [nodes](nodes/README.md) for the additional nodes installed with ComfyScript.
39 changes: 22 additions & 17 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,32 @@
success = False
print('\033[34mComfyScript: \033[91mPython 3.9+ is required.\033[0m')

try:
print('\033[34mComfyScript: \033[93mLoading nodes...\033[0m')
# If there are conflicts, the later one will override the former one.

from .nodes import ComfyUI_Ib_CustomNodes
NODE_CLASS_MAPPINGS.update(ComfyUI_Ib_CustomNodes.NODE_CLASS_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(ComfyUI_Ib_CustomNodes.NODE_DISPLAY_NAME_MAPPINGS)

from .nodes import comfyui_tooling_nodes
NODE_CLASS_MAPPINGS.update(comfyui_tooling_nodes.NODE_CLASS_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(comfyui_tooling_nodes.NODE_DISPLAY_NAME_MAPPINGS)
except (ImportError, AttributeError) as e:
root = Path(__file__).resolve().parent

# Replaced by prestartup_script.py
# try:
# print('\033[34mComfyScript: \033[93mLoading nodes...\033[0m')
# # If there are conflicts, the later one will override the former one.

# from .nodes import ComfyUI_Ib_CustomNodes
# NODE_CLASS_MAPPINGS.update(ComfyUI_Ib_CustomNodes.NODE_CLASS_MAPPINGS)
# NODE_DISPLAY_NAME_MAPPINGS.update(ComfyUI_Ib_CustomNodes.NODE_DISPLAY_NAME_MAPPINGS)
# except (ImportError, AttributeError) as e:
# success = False
# print(
# f'''\033[34mComfyScript: \033[91mFailed to load additional nodes due to missing submodules: {e}.
# If you need them, try to run:
# git -C "{root}" submodule update --init --recursive
# \033[0m''')

if not (root / 'nodes' / 'ComfyUI_Ib_CustomNodes' / '__init__.py').exists():
success = False
print(
f'''\033[34mComfyScript: \033[91mFailed to load nodes due to missing submodules: {e}.
If you need them, try to run:
git -C "{Path(__file__).resolve().parent}" submodule update --init --recursive
f'''\033[34mComfyScript: \033[91mFailed to load additional nodes due to missing submodules. If you need them, try to run:
git -C "{root}" submodule update --init --recursive
\033[0m''')

src = Path(__file__).resolve().parent / 'src'
sys.path.insert(0, str(src))
sys.path.insert(0, str(root / 'src'))
import comfy_script
success &= comfy_script.import_as_node

Expand Down
Empty file removed nodes/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions prestartup_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pathlib import Path

import folder_paths

folder_paths.add_model_folder_path('custom_nodes', Path(__file__).resolve().parent / 'nodes')

0 comments on commit 5aaf6ee

Please sign in to comment.