From 31c0cb9efb43b9bbf61297262f3420798a8f6ddf Mon Sep 17 00:00:00 2001 From: Chaoses-Ib Date: Sat, 15 Jun 2024 00:26:24 +0800 Subject: [PATCH] fix(transpile): pos dict and unknown end node in workflow (#42) --- src/comfy_script/transpile/__init__.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/comfy_script/transpile/__init__.py b/src/comfy_script/transpile/__init__.py index 0c8ad86..0c3c156 100644 --- a/src/comfy_script/transpile/__init__.py +++ b/src/comfy_script/transpile/__init__.py @@ -1,6 +1,7 @@ from __future__ import annotations import json from types import SimpleNamespace +from warnings import warn import networkx as nx @@ -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):