chore: regular input names

This commit is contained in:
bojiang
2024-11-06 19:00:50 +08:00
parent 7fee916636
commit f932ebb534
2 changed files with 34 additions and 8 deletions
+8 -8
View File
@@ -331,12 +331,12 @@ NODE_CLASS_MAPPINGS = {
}
NODE_DISPLAY_NAME_MAPPINGS = {
"BentoOutputPath": "Bento Path Output",
"BentoOutputImage": "Bento Image Output",
"BentoInputImage": "Bento Load Image",
"BentoInputString": "Bento String Input",
"BentoInputInteger": "Bento Integer Input",
"BentoInputFloat": "Bento Float Input",
"BentoInputBoolean": "Bento Boolean Input",
"BentoInputPath": "Bento Path Input",
"BentoOutputPath": "Path Output",
"BentoOutputImage": "Image Output",
"BentoInputImage": "Load Image",
"BentoInputString": "String Input",
"BentoInputInteger": "Integer Input",
"BentoInputFloat": "Float Input",
"BentoInputBoolean": "Boolean Input",
"BentoInputPath": "Path Input",
}
+26
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
import re
from pathlib import Path
from typing import TYPE_CHECKING
@@ -29,6 +30,21 @@ def _set_node_value(node: dict, value: any) -> None:
node["inputs"][key] = value
def _normalize_to_identifier(s: str) -> str:
if not s:
return "_"
s = re.sub(r"[^a-zA-Z0-9_]", "_", s)
if s[0].isdigit():
s = "_" + s
s = re.sub(r"_+", "_", s)
s = s.strip("_")
s = s if s else "_"
return s.lower()
def _parse_workflow(workflow: dict) -> tuple[dict, dict]:
"""
Parse the workflow template and return the input and output definition
@@ -39,10 +55,20 @@ def _parse_workflow(workflow: dict) -> tuple[dict, dict]:
for id, node in workflow.items():
if node["class_type"].startswith("BentoInput"):
name = node["_meta"]["title"]
if not name.isidentifier():
# format the name to be a valid python identifier
name = _normalize_to_identifier(name)
if name in inputs:
name = f"{name}_{id}"
node["id"] = id
inputs[name] = node
elif node["class_type"].startswith("BentoOutput"):
name = node["_meta"]["title"]
if not name.isidentifier():
# format the name to be a valid python identifier
name = _normalize_to_identifier(name)
if name in inputs:
name = f"{name}_{id}"
node["id"] = id
outputs[name] = node