Skip to content

Commit 5c5457a

Browse files
authored
support more example folders (#7836)
* support more example folders * add warning message
1 parent 45503f6 commit 5c5457a

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

app/custom_node_manager.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,20 @@ def build_translations(self):
9393

9494
def add_routes(self, routes, webapp, loadedModules):
9595

96+
example_workflow_folder_names = ["example_workflows", "example", "examples", "workflow", "workflows"]
97+
9698
@routes.get("/workflow_templates")
9799
async def get_workflow_templates(request):
98100
"""Returns a web response that contains the map of custom_nodes names and their associated workflow templates. The ones without templates are omitted."""
99-
files = [
100-
file
101-
for folder in folder_paths.get_folder_paths("custom_nodes")
102-
for file in glob.glob(
103-
os.path.join(folder, "*/example_workflows/*.json")
104-
)
105-
]
101+
102+
files = []
103+
104+
for folder in folder_paths.get_folder_paths("custom_nodes"):
105+
for folder_name in example_workflow_folder_names:
106+
pattern = os.path.join(folder, f"*/{folder_name}/*.json")
107+
matched_files = glob.glob(pattern)
108+
files.extend(matched_files)
109+
106110
workflow_templates_dict = (
107111
{}
108112
) # custom_nodes folder name -> example workflow names
@@ -118,15 +122,22 @@ async def get_workflow_templates(request):
118122

119123
# Serve workflow templates from custom nodes.
120124
for module_name, module_dir in loadedModules:
121-
workflows_dir = os.path.join(module_dir, "example_workflows")
122-
if os.path.exists(workflows_dir):
123-
webapp.add_routes(
124-
[
125-
web.static(
126-
"/api/workflow_templates/" + module_name, workflows_dir
127-
)
128-
]
129-
)
125+
for folder_name in example_workflow_folder_names:
126+
workflows_dir = os.path.join(module_dir, folder_name)
127+
128+
if os.path.exists(workflows_dir):
129+
if folder_name != "example_workflows":
130+
logging.warning(
131+
"WARNING: Found example workflow folder '%s' for custom node '%s', consider renaming it to 'example_workflows'",
132+
folder_name, module_name)
133+
134+
webapp.add_routes(
135+
[
136+
web.static(
137+
"/api/workflow_templates/" + module_name, workflows_dir
138+
)
139+
]
140+
)
130141

131142
@routes.get("/i18n")
132143
async def get_i18n(request):

0 commit comments

Comments
 (0)