Skip to content

Commit

Permalink
fix(transpile): UI-only node Reroute (rgthree) (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaoses-Ib committed Jun 13, 2024
1 parent cf46e1d commit 7355fde
Show file tree
Hide file tree
Showing 4 changed files with 517 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/comfy_script/transpile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ def _assign_id(self, name: str) -> str:
return name

def _get_input_types(self, node_type: str) -> dict:
# UI-only virtual nodes
# registerNodeType: Reroute, PrimitiveNode, Note
if node_type == 'Reroute':
if node_type in passes.REROUTE_NODES:
return {
'required': {
'': ('*',)
Expand All @@ -78,6 +79,8 @@ def _get_input_types(self, node_type: str) -> dict:
}
}
else:
if node_type not in self.nodes_info:
raise KeyError(f'Node not found: {node_type}. If this node is an UI-only virtual node (e.g. custom Reroute, PrimitiveNode, Note nodes), you can workaround this problem by exporting the API format workflow and transpiling it. You can report this issue in https://github.com/Chaoses-Ib/ComfyScript/issues .')
return self.nodes_info[node_type]['input']

def _get_widget_value_names(self, node_type: str) -> list[str]:
Expand Down
5 changes: 3 additions & 2 deletions src/comfy_script/transpile/passes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ class AssignContext:
vars: list
c: str

REROUTE_NODES = ('Reroute', 'Reroute (rgthree)')
def reroute_elimination(ctx: AssignContext):
if ctx.v.type != 'Reroute':
if ctx.v.type not in REROUTE_NODES:
return
assert re.fullmatch(r'(?:# )?(?:_ = Reroute\(\S+\)|(\S+) = Reroute\(\1\))\s*', ctx.c), ctx.c
assert re.fullmatch(r'(?:# )?(?:_ = [A-Za-z_0-9]+\(\S+\)|(\S+) = [A-Za-z_0-9]+\(\1\))\s*', ctx.c), ctx.c
ctx.c = ''

def bypass_move_elimination(ctx: AssignContext):
Expand Down
Loading

0 comments on commit 7355fde

Please sign in to comment.