-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serve workflow templates from custom_nodes #6193
Merged
comfyanonymous
merged 11 commits into
comfyanonymous:master
from
bezo97:feature/custom_workflow_templates
Dec 28, 2024
+83
−0
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b6e3bc2
add GET /workflow_templates
bezo97 547eb21
serve workflow templates from custom_nodes
bezo97 fc14655
refactor into custom_node_manager, add test
bezo97 e10cbad
Merge remote-tracking branch 'origin/master' into feature/custom_work…
bezo97 f04ad04
remove unused import
bezo97 f66d5cf
revert changes in folder_paths
bezo97 1ea319e
Merge remote-tracking branch 'origin/master' into feature/custom_work…
bezo97 c1f588a
Remove trailing whitespace.
comfyanonymous 1f583d2
account for multiple custom_nodes paths
bezo97 63dbf0c
Merge remote-tracking branch 'origin/master' into feature/custom_work…
bezo97 86cbe13
Merge branch 'feature/custom_workflow_templates' of https://github.co…
bezo97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import folder_paths | ||
import glob | ||
from aiohttp import web | ||
|
||
class CustomNodeManager: | ||
""" | ||
Placeholder to refactor the custom node management features from ComfyUI-Manager. | ||
Currently it only contains the custom workflow templates feature. | ||
""" | ||
def add_routes(self, routes, webapp, loadedModules): | ||
|
||
@routes.get("/workflow_templates") | ||
async def get_workflow_templates(request): | ||
"""Returns a web response that contains the map of custom_nodes names and their associated workflow templates. The ones without templates are omitted.""" | ||
files = glob.glob(os.path.join(folder_paths.get_folder_paths("custom_nodes")[0], '*/example_workflows/*.json')) | ||
workflow_templates_dict = {} # custom_nodes folder name -> example workflow names | ||
for file in files: | ||
custom_nodes_name = os.path.basename(os.path.dirname(os.path.dirname(file))) | ||
workflow_name = os.path.splitext(os.path.basename(file))[0] | ||
workflow_templates_dict.setdefault(custom_nodes_name, []).append(workflow_name) | ||
return web.json_response(workflow_templates_dict) | ||
|
||
# Serve workflow templates from custom nodes. | ||
for module_name, module_dir in loadedModules: | ||
workflows_dir = os.path.join(module_dir, 'example_workflows') | ||
if os.path.exists(workflows_dir): | ||
webapp.add_routes([web.static('/api/workflow_templates/' + module_name, workflows_dir)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
from aiohttp import web | ||
from unittest.mock import patch | ||
from app.custom_node_manager import CustomNodeManager | ||
|
||
pytestmark = ( | ||
pytest.mark.asyncio | ||
) # This applies the asyncio mark to all test functions in the module | ||
|
||
@pytest.fixture | ||
def custom_node_manager(): | ||
return CustomNodeManager() | ||
|
||
@pytest.fixture | ||
def app(custom_node_manager): | ||
app = web.Application() | ||
routes = web.RouteTableDef() | ||
custom_node_manager.add_routes(routes, app, [("ComfyUI-TestExtension1", "ComfyUI-TestExtension1")]) | ||
app.add_routes(routes) | ||
return app | ||
|
||
async def test_get_workflow_templates(aiohttp_client, app, tmp_path): | ||
client = await aiohttp_client(app) | ||
# Setup temporary custom nodes file structure with 1 workflow file | ||
custom_nodes_dir = tmp_path / "custom_nodes" | ||
example_workflows_dir = custom_nodes_dir / "ComfyUI-TestExtension1" / "example_workflows" | ||
example_workflows_dir.mkdir(parents=True) | ||
template_file = example_workflows_dir / "workflow1.json" | ||
template_file.write_text('') | ||
|
||
with patch('folder_paths.folder_names_and_paths', { | ||
'custom_nodes': ([str(custom_nodes_dir)], None) | ||
}): | ||
response = await client.get('/workflow_templates') | ||
assert response.status == 200 | ||
workflows_dict = await response.json() | ||
assert isinstance(workflows_dict, dict) | ||
assert "ComfyUI-TestExtension1" in workflows_dict | ||
assert isinstance(workflows_dict["ComfyUI-TestExtension1"], list) | ||
assert workflows_dict["ComfyUI-TestExtension1"][0] == "workflow1" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only seems to take into account the first custom node path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry didn't realize the logic that there could be more, fixed now