Skip to content

Commit

Permalink
fix(transpile): pos dict and unknown end node in workflow (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaoses-Ib committed Jun 14, 2024
1 parent e9fba39 commit 31c0cb9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/comfy_script/transpile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
import json
from types import SimpleNamespace
from warnings import warn

import networkx as nx

Expand Down Expand Up @@ -291,7 +292,20 @@ def _topological_generations_ordered_dfs(self, end_nodes: list[int | str] | None
# ↓
# Y
# The most top-left node has the smallest (x + y).
end_nodes.sort(key=lambda v: sum(G.nodes[v]['v'].pos))
def node_pos_sum(v):
node = G.nodes[v]
if 'v' not in node:
# e.g. ghostsquad.json
msg = f'Unkown output node: {v}'
warn(msg)
return 0
pos = node['v'].pos
if isinstance(pos, SimpleNamespace):
# e.g. ghostsquad.json
return getattr(pos, '0') + getattr(pos, '1')
else:
return sum(pos)
end_nodes.sort(key=node_pos_sum)

visited = set()
def visit(node):
Expand Down

0 comments on commit 31c0cb9

Please sign in to comment.