koode-taskgraph 0.1.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of koode-taskgraph might be problematic. Click here for more details.
- koode_taskgraph-0.3.0/LICENSE +21 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/PKG-INFO +3 -1
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/README.md +17 -5
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/koode_taskgraph.egg-info/PKG-INFO +3 -1
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/koode_taskgraph.egg-info/SOURCES.txt +1 -0
- koode_taskgraph-0.3.0/koode_taskgraph.egg-info/entry_points.txt +3 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/pyproject.toml +3 -3
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/cli.py +5 -5
- koode_taskgraph-0.3.0/taskgraph/core/executor.py +300 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/ui/properties.py +30 -2
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/tests/test_gui_plugins.py +72 -1
- koode_taskgraph-0.1.0/koode_taskgraph.egg-info/entry_points.txt +0 -3
- koode_taskgraph-0.1.0/taskgraph/core/executor.py +0 -232
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/koode_taskgraph.egg-info/dependency_links.txt +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/koode_taskgraph.egg-info/requires.txt +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/koode_taskgraph.egg-info/top_level.txt +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/setup.cfg +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/__init__.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/__main__.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/app.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/core/__init__.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/core/model.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/core/registry.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/core/serialization.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/nodes/__init__.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/nodes/builtin.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/ui/__init__.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/ui/items.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/ui/main_window.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/ui/plugins.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/ui/scene.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/taskgraph/ui/theme.py +0 -0
- {koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/tests/test_core.py +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 koodelabs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: koode-taskgraph
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: An extensible process node graph built with QtPy and PySide6
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
|
+
License-File: LICENSE
|
|
6
7
|
Requires-Dist: PySide6>=6.7
|
|
7
8
|
Requires-Dist: QtPy>=2.4
|
|
9
|
+
Dynamic: license-file
|
|
@@ -3,29 +3,32 @@
|
|
|
3
3
|
TaskGraph is a small, extensible process graph editor built from scratch with
|
|
4
4
|
Python, QtPy, and PySide6.
|
|
5
5
|
|
|
6
|
+

|
|
7
|
+
|
|
6
8
|
## Run
|
|
7
9
|
|
|
8
10
|
```bash
|
|
9
11
|
python -m venv .venv
|
|
10
12
|
source .venv/bin/activate
|
|
11
13
|
python -m pip install koode-taskgraph
|
|
12
|
-
taskgraph
|
|
14
|
+
koode-taskgraph
|
|
13
15
|
```
|
|
14
16
|
|
|
15
17
|
For local development from this repository, use `python -m pip install -e .`.
|
|
18
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for pull request guidelines.
|
|
16
19
|
|
|
17
20
|
## Headless CLI
|
|
18
21
|
|
|
19
22
|
Execute a saved graph without starting Qt or opening a window:
|
|
20
23
|
|
|
21
24
|
```bash
|
|
22
|
-
|
|
25
|
+
koode-taskgraph-cli --file /path/to/workflow.taskgraph
|
|
23
26
|
```
|
|
24
27
|
|
|
25
28
|
Select the worker count and load external node locations when needed:
|
|
26
29
|
|
|
27
30
|
```bash
|
|
28
|
-
|
|
31
|
+
koode-taskgraph-cli \
|
|
29
32
|
--file /path/to/workflow.taskgraph \
|
|
30
33
|
--workers 8 \
|
|
31
34
|
--node-path /path/to/custom_nodes
|
|
@@ -65,6 +68,11 @@ class PrefixText(ProcessNode):
|
|
|
65
68
|
return {"text": f"{self.prefix}{inputs.get('value', '')}"}
|
|
66
69
|
```
|
|
67
70
|
|
|
71
|
+
Property kinds map to generated controls in the Properties panel: `"text"` for
|
|
72
|
+
a line edit, `"file"` for a file path field with a Browse button, `"bool"` for
|
|
73
|
+
a checkbox, `"int"`/`"float"` for numeric fields, and `"choice"` for a
|
|
74
|
+
dropdown using `choices`.
|
|
75
|
+
|
|
68
76
|
Modules in `taskgraph/nodes/` are discovered automatically. Custom modules can
|
|
69
77
|
also live anywhere on disk:
|
|
70
78
|
|
|
@@ -77,7 +85,7 @@ directories with the platform path separator (`:` on macOS/Linux and `;` on
|
|
|
77
85
|
Windows):
|
|
78
86
|
|
|
79
87
|
```bash
|
|
80
|
-
TASKGRAPH_NODE_PATH="/path/to/company_nodes:/path/to/my_nodes" taskgraph
|
|
88
|
+
TASKGRAPH_NODE_PATH="/path/to/company_nodes:/path/to/my_nodes" koode-taskgraph
|
|
81
89
|
```
|
|
82
90
|
|
|
83
91
|
Files beginning with `_` are ignored. Importing a custom node module executes
|
|
@@ -129,9 +137,13 @@ TaskGraph reloads saved plugin locations automatically. Alternatively, set
|
|
|
129
137
|
`TASKGRAPH_PLUGIN_PATH` before launching, using the same platform path
|
|
130
138
|
separator rules as `TASKGRAPH_NODE_PATH`.
|
|
131
139
|
|
|
140
|
+
This repository includes minimal example plugins in `examples/gui_plugins`.
|
|
141
|
+
Load that directory, then run **Examples → Create Hello World Print Graph** or
|
|
142
|
+
**Examples → Create Bingooo Print Graph**.
|
|
143
|
+
|
|
132
144
|
GUI plugins are intentionally separate from custom node locations. The
|
|
133
145
|
headless CLI loads `TASKGRAPH_NODE_PATH` only, so UI plugin code can safely
|
|
134
|
-
import Qt widgets without breaking `
|
|
146
|
+
import Qt widgets without breaking `koode-taskgraph-cli`.
|
|
135
147
|
|
|
136
148
|
## Controls
|
|
137
149
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: koode-taskgraph
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: An extensible process node graph built with QtPy and PySide6
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
|
+
License-File: LICENSE
|
|
6
7
|
Requires-Dist: PySide6>=6.7
|
|
7
8
|
Requires-Dist: QtPy>=2.4
|
|
9
|
+
Dynamic: license-file
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "koode-taskgraph"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
description = "An extensible process node graph built with QtPy and PySide6"
|
|
9
9
|
requires-python = ">=3.10"
|
|
10
10
|
dependencies = [
|
|
@@ -13,8 +13,8 @@ dependencies = [
|
|
|
13
13
|
]
|
|
14
14
|
|
|
15
15
|
[project.scripts]
|
|
16
|
-
taskgraph = "taskgraph.app:main"
|
|
17
|
-
|
|
16
|
+
koode-taskgraph = "taskgraph.app:main"
|
|
17
|
+
koode-taskgraph-cli = "taskgraph.cli:main"
|
|
18
18
|
|
|
19
19
|
[tool.setuptools.packages.find]
|
|
20
20
|
include = ["taskgraph*"]
|
|
@@ -35,7 +35,7 @@ def worker_count(value: str) -> int:
|
|
|
35
35
|
|
|
36
36
|
def build_parser() -> argparse.ArgumentParser:
|
|
37
37
|
parser = argparse.ArgumentParser(
|
|
38
|
-
prog="
|
|
38
|
+
prog="koode-taskgraph-cli",
|
|
39
39
|
description="Execute a TaskGraph file without starting the Qt UI.",
|
|
40
40
|
)
|
|
41
41
|
parser.add_argument(
|
|
@@ -65,7 +65,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
65
65
|
args = build_parser().parse_args(argv)
|
|
66
66
|
graph_path = args.file.expanduser()
|
|
67
67
|
if not graph_path.is_file():
|
|
68
|
-
print(f"
|
|
68
|
+
print(f"koode-taskgraph-cli: graph file not found: {graph_path}", file=sys.stderr)
|
|
69
69
|
return 2
|
|
70
70
|
|
|
71
71
|
try:
|
|
@@ -79,7 +79,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
79
79
|
load_custom_node_directory(location)
|
|
80
80
|
graph = load_graph(graph_path)
|
|
81
81
|
except Exception as exc:
|
|
82
|
-
print(f"
|
|
82
|
+
print(f"koode-taskgraph-cli: could not load graph: {exc}", file=sys.stderr)
|
|
83
83
|
return 2
|
|
84
84
|
|
|
85
85
|
cancel_event = Event()
|
|
@@ -101,10 +101,10 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
101
101
|
cancel_event=cancel_event,
|
|
102
102
|
)
|
|
103
103
|
except GraphExecutionCancelled as exc:
|
|
104
|
-
print(f"
|
|
104
|
+
print(f"koode-taskgraph-cli: {exc}", file=sys.stderr)
|
|
105
105
|
return 130
|
|
106
106
|
except GraphExecutionError as exc:
|
|
107
|
-
print(f"
|
|
107
|
+
print(f"koode-taskgraph-cli: execution failed:\n{exc}", file=sys.stderr)
|
|
108
108
|
return 1
|
|
109
109
|
finally:
|
|
110
110
|
signal.signal(signal.SIGINT, previous_handler)
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections import defaultdict, deque
|
|
4
|
+
from concurrent.futures import FIRST_COMPLETED, Future, ThreadPoolExecutor, wait
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from threading import Event
|
|
7
|
+
from typing import Any, Callable
|
|
8
|
+
|
|
9
|
+
from taskgraph.core.model import Connection, Graph, NodeCancelled
|
|
10
|
+
|
|
11
|
+
VALID_WORKER_COUNTS = (1, *range(2, 33, 2))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class GraphExecutionError(RuntimeError):
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class GraphExecutionCancelled(GraphExecutionError):
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class ExecutionResult:
|
|
24
|
+
order: list[str]
|
|
25
|
+
outputs: dict[str, dict[str, Any]]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def execute_graph(
|
|
29
|
+
graph: Graph,
|
|
30
|
+
on_event: Callable[[str], None] | None = None,
|
|
31
|
+
max_workers: int = 4,
|
|
32
|
+
on_node_state: Callable[[str, str], None] | None = None,
|
|
33
|
+
cancel_event: Event | None = None,
|
|
34
|
+
) -> ExecutionResult:
|
|
35
|
+
return GraphExecutor(
|
|
36
|
+
graph,
|
|
37
|
+
on_event=on_event,
|
|
38
|
+
on_node_state=on_node_state,
|
|
39
|
+
cancel_event=cancel_event,
|
|
40
|
+
).execute(max_workers=max_workers)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class GraphExecutor:
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
graph: Graph,
|
|
47
|
+
on_event: Callable[[str], None] | None = None,
|
|
48
|
+
on_node_state: Callable[[str, str], None] | None = None,
|
|
49
|
+
cancel_event: Event | None = None,
|
|
50
|
+
):
|
|
51
|
+
self.graph = graph
|
|
52
|
+
self.emit = on_event or (lambda _message: None)
|
|
53
|
+
self.set_state = on_node_state or (lambda _node_id, _state: None)
|
|
54
|
+
self.cancel_event = cancel_event or Event()
|
|
55
|
+
self.indegree = {node_id: 0 for node_id in graph.nodes}
|
|
56
|
+
self.downstream: dict[str, list[str]] = defaultdict(list)
|
|
57
|
+
self.incoming: dict[str, list[Connection]] = defaultdict(list)
|
|
58
|
+
self.attribute_edges: list[Connection] = []
|
|
59
|
+
self.queue: deque[str] = deque()
|
|
60
|
+
self.order: list[str] = []
|
|
61
|
+
self.outputs: dict[str, dict[str, Any]] = {}
|
|
62
|
+
self.terminal: set[str] = set()
|
|
63
|
+
self.failures: list[str] = []
|
|
64
|
+
self.running: dict[Future[dict[str, Any]], str] = {}
|
|
65
|
+
self.cancellation_applied = False
|
|
66
|
+
|
|
67
|
+
def execute(self, max_workers: int = 4) -> ExecutionResult:
|
|
68
|
+
self._validate_worker_count(max_workers)
|
|
69
|
+
self._prepare_connections()
|
|
70
|
+
self._validate_attribute_dependencies()
|
|
71
|
+
self.queue = deque(
|
|
72
|
+
node_id for node_id, degree in self.indegree.items()
|
|
73
|
+
if degree == 0
|
|
74
|
+
)
|
|
75
|
+
self._run(max_workers)
|
|
76
|
+
self._raise_if_cancelled()
|
|
77
|
+
self._raise_if_unresolved_or_failed()
|
|
78
|
+
return ExecutionResult(self.order, self.outputs)
|
|
79
|
+
|
|
80
|
+
@staticmethod
|
|
81
|
+
def _validate_worker_count(max_workers: int) -> None:
|
|
82
|
+
if max_workers not in VALID_WORKER_COUNTS:
|
|
83
|
+
raise ValueError(
|
|
84
|
+
"max_workers must be 1 or an even number between 2 and 32"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def _prepare_connections(self) -> None:
|
|
88
|
+
for edge in self.graph.connections:
|
|
89
|
+
if (
|
|
90
|
+
edge.source_node not in self.graph.nodes
|
|
91
|
+
or edge.target_node not in self.graph.nodes
|
|
92
|
+
):
|
|
93
|
+
raise GraphExecutionError("A connection references a missing node")
|
|
94
|
+
if edge.kind == "dependency":
|
|
95
|
+
self.indegree[edge.target_node] += 1
|
|
96
|
+
self.downstream[edge.source_node].append(edge.target_node)
|
|
97
|
+
else:
|
|
98
|
+
self.attribute_edges.append(edge)
|
|
99
|
+
self.incoming[edge.target_node].append(edge)
|
|
100
|
+
|
|
101
|
+
def _validate_attribute_dependencies(self) -> None:
|
|
102
|
+
for edge in self.attribute_edges:
|
|
103
|
+
if not self._has_dependency_path(edge.source_node, edge.target_node):
|
|
104
|
+
source = self.graph.nodes[edge.source_node]
|
|
105
|
+
target = self.graph.nodes[edge.target_node]
|
|
106
|
+
raise GraphExecutionError(
|
|
107
|
+
f"Attribute {source.display_name}.{edge.source_port} -> "
|
|
108
|
+
f"{target.display_name}.{edge.target_port} requires a dependency path"
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
def _has_dependency_path(self, source: str, target: str) -> bool:
|
|
112
|
+
pending = [source]
|
|
113
|
+
visited = set()
|
|
114
|
+
while pending:
|
|
115
|
+
current = pending.pop()
|
|
116
|
+
if current == target:
|
|
117
|
+
return True
|
|
118
|
+
if current not in visited:
|
|
119
|
+
visited.add(current)
|
|
120
|
+
pending.extend(self.downstream[current])
|
|
121
|
+
return False
|
|
122
|
+
|
|
123
|
+
def _run(self, max_workers: int) -> None:
|
|
124
|
+
with ThreadPoolExecutor(
|
|
125
|
+
max_workers=max_workers,
|
|
126
|
+
thread_name_prefix="taskgraph",
|
|
127
|
+
) as pool:
|
|
128
|
+
while self.queue or self.running:
|
|
129
|
+
self._apply_cancellation_if_requested()
|
|
130
|
+
self._submit_ready_nodes(pool, max_workers)
|
|
131
|
+
if not self.running:
|
|
132
|
+
continue
|
|
133
|
+
finished, _pending = wait(
|
|
134
|
+
self.running,
|
|
135
|
+
return_when=FIRST_COMPLETED,
|
|
136
|
+
)
|
|
137
|
+
self._handle_finished_futures(finished)
|
|
138
|
+
|
|
139
|
+
def _apply_cancellation_if_requested(self) -> None:
|
|
140
|
+
if not self.cancel_event.is_set() or self.cancellation_applied:
|
|
141
|
+
return
|
|
142
|
+
self.cancellation_applied = True
|
|
143
|
+
self.emit("Cancellation requested...")
|
|
144
|
+
running_ids = set(self.running.values())
|
|
145
|
+
for future in self.running:
|
|
146
|
+
future.cancel()
|
|
147
|
+
for node_id in self.graph.nodes:
|
|
148
|
+
if node_id not in self.terminal and node_id not in running_ids:
|
|
149
|
+
self.terminal.add(node_id)
|
|
150
|
+
self.set_state(node_id, "cancelled")
|
|
151
|
+
self.queue.clear()
|
|
152
|
+
|
|
153
|
+
def _submit_ready_nodes(
|
|
154
|
+
self,
|
|
155
|
+
pool: ThreadPoolExecutor,
|
|
156
|
+
max_workers: int,
|
|
157
|
+
) -> None:
|
|
158
|
+
while self.queue and len(self.running) < max_workers:
|
|
159
|
+
node_id = self.queue.popleft()
|
|
160
|
+
if node_id in self.terminal:
|
|
161
|
+
continue
|
|
162
|
+
node = self.graph.nodes[node_id]
|
|
163
|
+
if node.disabled:
|
|
164
|
+
self.emit(f"Skipped disabled node: {node.display_name}")
|
|
165
|
+
self.set_state(node_id, "skipped")
|
|
166
|
+
self._complete(node_id, {})
|
|
167
|
+
continue
|
|
168
|
+
try:
|
|
169
|
+
node_inputs = self._inputs_for(node_id)
|
|
170
|
+
except GraphExecutionError as exc:
|
|
171
|
+
self._fail_branch(node_id, str(exc))
|
|
172
|
+
continue
|
|
173
|
+
self.emit(f"Running {node.display_name}")
|
|
174
|
+
self.set_state(node_id, "running")
|
|
175
|
+
node._cancel_event = self.cancel_event
|
|
176
|
+
self.running[pool.submit(node.process, node_inputs)] = node_id
|
|
177
|
+
|
|
178
|
+
def _inputs_for(self, node_id: str) -> dict[str, Any]:
|
|
179
|
+
node = self.graph.nodes[node_id]
|
|
180
|
+
node_inputs: dict[str, Any] = {}
|
|
181
|
+
for edge in self.incoming[node_id]:
|
|
182
|
+
source_outputs = self.outputs.get(edge.source_node, {})
|
|
183
|
+
if edge.source_port not in source_outputs:
|
|
184
|
+
source = self.graph.nodes[edge.source_node]
|
|
185
|
+
raise GraphExecutionError(
|
|
186
|
+
f"{node.display_name}: input '{edge.target_port}' is unavailable "
|
|
187
|
+
f"because {source.display_name} did not produce '{edge.source_port}'"
|
|
188
|
+
)
|
|
189
|
+
value = source_outputs[edge.source_port]
|
|
190
|
+
port = next(
|
|
191
|
+
spec for spec in node.inputs
|
|
192
|
+
if spec.name == edge.target_port
|
|
193
|
+
)
|
|
194
|
+
if port.multiple:
|
|
195
|
+
node_inputs.setdefault(edge.target_port, []).append(value)
|
|
196
|
+
else:
|
|
197
|
+
node_inputs[edge.target_port] = value
|
|
198
|
+
|
|
199
|
+
missing = [
|
|
200
|
+
port.name for port in node.inputs
|
|
201
|
+
if port.required and port.name not in node_inputs
|
|
202
|
+
]
|
|
203
|
+
if missing:
|
|
204
|
+
raise GraphExecutionError(
|
|
205
|
+
f"{node.display_name}: missing required input(s): {', '.join(missing)}"
|
|
206
|
+
)
|
|
207
|
+
return node_inputs
|
|
208
|
+
|
|
209
|
+
def _handle_finished_futures(
|
|
210
|
+
self,
|
|
211
|
+
finished: set[Future[dict[str, Any]]],
|
|
212
|
+
) -> None:
|
|
213
|
+
for future in finished:
|
|
214
|
+
node_id = self.running.pop(future)
|
|
215
|
+
node = self.graph.nodes[node_id]
|
|
216
|
+
try:
|
|
217
|
+
if self.cancel_event.is_set():
|
|
218
|
+
self._discard_cancelled_future(future)
|
|
219
|
+
self._mark_cancelled(node_id)
|
|
220
|
+
continue
|
|
221
|
+
result = future.result()
|
|
222
|
+
except NodeCancelled:
|
|
223
|
+
self._mark_cancelled(node_id)
|
|
224
|
+
continue
|
|
225
|
+
except Exception as exc:
|
|
226
|
+
self._fail_branch(node_id, f"{node.display_name} failed: {exc}")
|
|
227
|
+
continue
|
|
228
|
+
finally:
|
|
229
|
+
node._cancel_event = None
|
|
230
|
+
|
|
231
|
+
if not isinstance(result, dict):
|
|
232
|
+
self._fail_branch(
|
|
233
|
+
node_id,
|
|
234
|
+
f"{node.display_name} must return a dictionary",
|
|
235
|
+
)
|
|
236
|
+
continue
|
|
237
|
+
self._complete(node_id, result)
|
|
238
|
+
self.set_state(node_id, "finished")
|
|
239
|
+
self.emit(f"Finished {node.display_name}: {result}")
|
|
240
|
+
|
|
241
|
+
@staticmethod
|
|
242
|
+
def _discard_cancelled_future(future: Future[dict[str, Any]]) -> None:
|
|
243
|
+
try:
|
|
244
|
+
future.result()
|
|
245
|
+
except Exception:
|
|
246
|
+
pass
|
|
247
|
+
|
|
248
|
+
def _mark_cancelled(self, node_id: str) -> None:
|
|
249
|
+
node = self.graph.nodes[node_id]
|
|
250
|
+
self.terminal.add(node_id)
|
|
251
|
+
self.set_state(node_id, "cancelled")
|
|
252
|
+
self.emit(f"Cancelled {node.display_name}")
|
|
253
|
+
|
|
254
|
+
def _complete(self, node_id: str, result: dict[str, Any]) -> None:
|
|
255
|
+
self.outputs[node_id] = result
|
|
256
|
+
self.order.append(node_id)
|
|
257
|
+
self.terminal.add(node_id)
|
|
258
|
+
for target in self.downstream[node_id]:
|
|
259
|
+
self.indegree[target] -= 1
|
|
260
|
+
if self.indegree[target] == 0:
|
|
261
|
+
self.queue.append(target)
|
|
262
|
+
|
|
263
|
+
def _fail_branch(self, node_id: str, message: str) -> None:
|
|
264
|
+
"""Fail one node and block only nodes that depend on its output."""
|
|
265
|
+
if node_id in self.terminal:
|
|
266
|
+
return
|
|
267
|
+
self.terminal.add(node_id)
|
|
268
|
+
self.failures.append(message)
|
|
269
|
+
self.set_state(node_id, "failed")
|
|
270
|
+
self.emit(f"Failure: {message}")
|
|
271
|
+
pending = deque(self.downstream[node_id])
|
|
272
|
+
while pending:
|
|
273
|
+
blocked_id = pending.popleft()
|
|
274
|
+
if blocked_id in self.terminal:
|
|
275
|
+
continue
|
|
276
|
+
self.terminal.add(blocked_id)
|
|
277
|
+
self.set_state(blocked_id, "blocked")
|
|
278
|
+
self.emit(
|
|
279
|
+
f"Blocked {self.graph.nodes[blocked_id].display_name}: "
|
|
280
|
+
"an upstream dependency failed"
|
|
281
|
+
)
|
|
282
|
+
pending.extend(self.downstream[blocked_id])
|
|
283
|
+
|
|
284
|
+
def _raise_if_cancelled(self) -> None:
|
|
285
|
+
if not self.cancel_event.is_set():
|
|
286
|
+
return
|
|
287
|
+
for node_id in self.graph.nodes:
|
|
288
|
+
if node_id not in self.terminal:
|
|
289
|
+
self.terminal.add(node_id)
|
|
290
|
+
self.set_state(node_id, "cancelled")
|
|
291
|
+
raise GraphExecutionCancelled("Graph execution cancelled")
|
|
292
|
+
|
|
293
|
+
def _raise_if_unresolved_or_failed(self) -> None:
|
|
294
|
+
unresolved = set(self.graph.nodes) - self.terminal
|
|
295
|
+
if unresolved:
|
|
296
|
+
self.failures.append("The graph contains a cycle and cannot be executed")
|
|
297
|
+
for node_id in unresolved:
|
|
298
|
+
self.set_state(node_id, "blocked")
|
|
299
|
+
if self.failures:
|
|
300
|
+
raise GraphExecutionError("\n".join(self.failures))
|
|
@@ -3,8 +3,9 @@ from __future__ import annotations
|
|
|
3
3
|
from qtpy.QtCore import Signal
|
|
4
4
|
from qtpy.QtGui import QColor
|
|
5
5
|
from qtpy.QtWidgets import (
|
|
6
|
-
QCheckBox, QComboBox, QDoubleSpinBox,
|
|
7
|
-
|
|
6
|
+
QCheckBox, QComboBox, QDoubleSpinBox, QFileDialog, QFormLayout,
|
|
7
|
+
QHBoxLayout, QLabel, QLineEdit, QPushButton, QScrollArea, QSizePolicy,
|
|
8
|
+
QSpinBox, QTextEdit, QWidget,
|
|
8
9
|
)
|
|
9
10
|
|
|
10
11
|
from taskgraph.core.model import Backdrop
|
|
@@ -128,11 +129,38 @@ class PropertyEditor(QScrollArea):
|
|
|
128
129
|
widget.currentIndexChanged.connect(
|
|
129
130
|
lambda index, s=spec: self._set(s.name, s.choices[index])
|
|
130
131
|
)
|
|
132
|
+
elif spec.kind == "file":
|
|
133
|
+
widget = self._make_file_editor(spec, value)
|
|
131
134
|
else:
|
|
132
135
|
widget = QLineEdit("" if value is None else str(value))
|
|
133
136
|
widget.editingFinished.connect(lambda w=widget, s=spec: self._set(s.name, w.text()))
|
|
134
137
|
return widget
|
|
135
138
|
|
|
139
|
+
def _make_file_editor(self, spec, value) -> QWidget:
|
|
140
|
+
widget = QWidget()
|
|
141
|
+
layout = QHBoxLayout(widget)
|
|
142
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
143
|
+
layout.setSpacing(6)
|
|
144
|
+
path = QLineEdit("" if value is None else str(value))
|
|
145
|
+
browse = QPushButton("Browse...")
|
|
146
|
+
browse.clicked.connect(
|
|
147
|
+
lambda checked=False, editor=path, s=spec: self._browse_file(editor, s)
|
|
148
|
+
)
|
|
149
|
+
path.editingFinished.connect(
|
|
150
|
+
lambda editor=path, s=spec: self._set(s.name, editor.text())
|
|
151
|
+
)
|
|
152
|
+
layout.addWidget(path, 1)
|
|
153
|
+
layout.addWidget(browse)
|
|
154
|
+
return widget
|
|
155
|
+
|
|
156
|
+
def _browse_file(self, editor: QLineEdit, spec) -> None:
|
|
157
|
+
filename, _ = QFileDialog.getOpenFileName(
|
|
158
|
+
self, f"Select {spec.label}", editor.text()
|
|
159
|
+
)
|
|
160
|
+
if filename:
|
|
161
|
+
editor.setText(filename)
|
|
162
|
+
self._set(spec.name, filename)
|
|
163
|
+
|
|
136
164
|
def _set(self, name, value) -> None:
|
|
137
165
|
if self._node:
|
|
138
166
|
self._node.values[name] = value
|
|
@@ -5,12 +5,16 @@ import unittest
|
|
|
5
5
|
|
|
6
6
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
7
7
|
|
|
8
|
-
from qtpy.QtWidgets import QApplication
|
|
8
|
+
from qtpy.QtWidgets import QApplication, QLineEdit, QWidget
|
|
9
9
|
|
|
10
10
|
from taskgraph.nodes import load_builtin_nodes
|
|
11
|
+
from taskgraph.core.model import Graph, NodeProperty, ProcessNode
|
|
11
12
|
from taskgraph.ui.main_window import MainWindow
|
|
13
|
+
from taskgraph.ui.properties import PropertyEditor
|
|
12
14
|
from taskgraph.ui.plugins import load_gui_plugin_directory
|
|
13
15
|
|
|
16
|
+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
17
|
+
|
|
14
18
|
|
|
15
19
|
class GuiPluginTests(unittest.TestCase):
|
|
16
20
|
@classmethod
|
|
@@ -83,6 +87,73 @@ class GuiPluginTests(unittest.TestCase):
|
|
|
83
87
|
self.assertEqual(len(backdrops), 1)
|
|
84
88
|
self.assertEqual(backdrops[0].title, "Plugin Notes")
|
|
85
89
|
|
|
90
|
+
def test_example_print_plugins(self):
|
|
91
|
+
plugin_directory = PROJECT_ROOT / "examples" / "gui_plugins"
|
|
92
|
+
loaded = load_gui_plugin_directory(plugin_directory, self.window)
|
|
93
|
+
self.assertIn(plugin_directory / "hello_world_print.py", loaded)
|
|
94
|
+
self.assertIn(plugin_directory / "bingooo_print.py", loaded)
|
|
95
|
+
|
|
96
|
+
self._trigger_example_and_assert_graph(
|
|
97
|
+
action_text="Create Hello World Print Graph",
|
|
98
|
+
node_names=["Hello World Text", "Print Hello World"],
|
|
99
|
+
text_value="hello world",
|
|
100
|
+
)
|
|
101
|
+
self.window.scene.set_graph(Graph())
|
|
102
|
+
self.window.dirty = False
|
|
103
|
+
self._trigger_example_and_assert_graph(
|
|
104
|
+
action_text="Create Bingooo Print Graph",
|
|
105
|
+
node_names=["Bingooo Text", "Print Bingooo"],
|
|
106
|
+
text_value="Bingooo!!",
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
def _trigger_example_and_assert_graph(self, action_text, node_names, text_value):
|
|
110
|
+
examples_menu = self.window.menus["examples"]
|
|
111
|
+
actions = [
|
|
112
|
+
action for action in examples_menu.actions()
|
|
113
|
+
if action.text() == action_text
|
|
114
|
+
]
|
|
115
|
+
self.assertEqual(len(actions), 1)
|
|
116
|
+
actions[0].trigger()
|
|
117
|
+
|
|
118
|
+
nodes = list(self.window.scene.graph.nodes.values())
|
|
119
|
+
self.assertEqual([node.display_name for node in nodes], node_names)
|
|
120
|
+
self.assertEqual(nodes[0].type_id, "input.text")
|
|
121
|
+
self.assertEqual(nodes[0].values["text"], text_value)
|
|
122
|
+
self.assertEqual(nodes[1].type_id, "output.print")
|
|
123
|
+
self.assertEqual(len(self.window.scene.graph.connections), 2)
|
|
124
|
+
self.assertEqual(
|
|
125
|
+
{connection.kind for connection in self.window.scene.graph.connections},
|
|
126
|
+
{"attribute", "dependency"},
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class PropertyEditorTests(unittest.TestCase):
|
|
131
|
+
@classmethod
|
|
132
|
+
def setUpClass(cls):
|
|
133
|
+
cls.app = QApplication.instance() or QApplication([])
|
|
134
|
+
|
|
135
|
+
def test_file_property_uses_browse_widget_and_stores_text_path(self):
|
|
136
|
+
class FileNode(ProcessNode):
|
|
137
|
+
title = "File Node"
|
|
138
|
+
type_id = "tests.file_node"
|
|
139
|
+
properties = (
|
|
140
|
+
NodeProperty("source_file", "Source File", "file", ""),
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
node = FileNode()
|
|
144
|
+
editor = PropertyEditor()
|
|
145
|
+
editor.set_node(node)
|
|
146
|
+
|
|
147
|
+
file_widgets = [
|
|
148
|
+
widget for widget in editor.findChildren(QWidget)
|
|
149
|
+
if widget.findChild(QLineEdit)
|
|
150
|
+
]
|
|
151
|
+
path_editor = file_widgets[-1].findChild(QLineEdit)
|
|
152
|
+
path_editor.setText("/tmp/example.txt")
|
|
153
|
+
path_editor.editingFinished.emit()
|
|
154
|
+
|
|
155
|
+
self.assertEqual(node.values["source_file"], "/tmp/example.txt")
|
|
156
|
+
|
|
86
157
|
|
|
87
158
|
if __name__ == "__main__":
|
|
88
159
|
unittest.main()
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from collections import defaultdict, deque
|
|
4
|
-
from concurrent.futures import FIRST_COMPLETED, ThreadPoolExecutor, wait
|
|
5
|
-
from dataclasses import dataclass
|
|
6
|
-
from threading import Event
|
|
7
|
-
from typing import Any, Callable
|
|
8
|
-
|
|
9
|
-
from taskgraph.core.model import Graph, NodeCancelled
|
|
10
|
-
|
|
11
|
-
VALID_WORKER_COUNTS = (1, *range(2, 33, 2))
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class GraphExecutionError(RuntimeError):
|
|
15
|
-
pass
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class GraphExecutionCancelled(GraphExecutionError):
|
|
19
|
-
pass
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@dataclass
|
|
23
|
-
class ExecutionResult:
|
|
24
|
-
order: list[str]
|
|
25
|
-
outputs: dict[str, dict[str, Any]]
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def execute_graph(
|
|
29
|
-
graph: Graph,
|
|
30
|
-
on_event: Callable[[str], None] | None = None,
|
|
31
|
-
max_workers: int = 4,
|
|
32
|
-
on_node_state: Callable[[str, str], None] | None = None,
|
|
33
|
-
cancel_event: Event | None = None,
|
|
34
|
-
) -> ExecutionResult:
|
|
35
|
-
if max_workers not in VALID_WORKER_COUNTS:
|
|
36
|
-
raise ValueError(
|
|
37
|
-
"max_workers must be 1 or an even number between 2 and 32"
|
|
38
|
-
)
|
|
39
|
-
emit = on_event or (lambda _message: None)
|
|
40
|
-
set_state = on_node_state or (lambda _node_id, _state: None)
|
|
41
|
-
cancel_event = cancel_event or Event()
|
|
42
|
-
indegree = {node_id: 0 for node_id in graph.nodes}
|
|
43
|
-
downstream: dict[str, list[str]] = defaultdict(list)
|
|
44
|
-
incoming = defaultdict(list)
|
|
45
|
-
|
|
46
|
-
attribute_edges = []
|
|
47
|
-
for edge in graph.connections:
|
|
48
|
-
if edge.source_node not in graph.nodes or edge.target_node not in graph.nodes:
|
|
49
|
-
raise GraphExecutionError("A connection references a missing node")
|
|
50
|
-
if edge.kind == "dependency":
|
|
51
|
-
indegree[edge.target_node] += 1
|
|
52
|
-
downstream[edge.source_node].append(edge.target_node)
|
|
53
|
-
else:
|
|
54
|
-
attribute_edges.append(edge)
|
|
55
|
-
incoming[edge.target_node].append(edge)
|
|
56
|
-
|
|
57
|
-
def has_dependency_path(source: str, target: str) -> bool:
|
|
58
|
-
pending = [source]
|
|
59
|
-
visited = set()
|
|
60
|
-
while pending:
|
|
61
|
-
current = pending.pop()
|
|
62
|
-
if current == target:
|
|
63
|
-
return True
|
|
64
|
-
if current not in visited:
|
|
65
|
-
visited.add(current)
|
|
66
|
-
pending.extend(downstream[current])
|
|
67
|
-
return False
|
|
68
|
-
|
|
69
|
-
for edge in attribute_edges:
|
|
70
|
-
if not has_dependency_path(edge.source_node, edge.target_node):
|
|
71
|
-
source = graph.nodes[edge.source_node]
|
|
72
|
-
target = graph.nodes[edge.target_node]
|
|
73
|
-
raise GraphExecutionError(
|
|
74
|
-
f"Attribute {source.display_name}.{edge.source_port} → "
|
|
75
|
-
f"{target.display_name}.{edge.target_port} requires a dependency path"
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
queue = deque(node_id for node_id, degree in indegree.items() if degree == 0)
|
|
79
|
-
order: list[str] = []
|
|
80
|
-
outputs: dict[str, dict[str, Any]] = {}
|
|
81
|
-
terminal: set[str] = set()
|
|
82
|
-
failures: list[str] = []
|
|
83
|
-
|
|
84
|
-
def inputs_for(node_id: str) -> dict[str, Any]:
|
|
85
|
-
node = graph.nodes[node_id]
|
|
86
|
-
node_inputs: dict[str, Any] = {}
|
|
87
|
-
for edge in incoming[node_id]:
|
|
88
|
-
source_outputs = outputs.get(edge.source_node, {})
|
|
89
|
-
if edge.source_port not in source_outputs:
|
|
90
|
-
source = graph.nodes[edge.source_node]
|
|
91
|
-
raise GraphExecutionError(
|
|
92
|
-
f"{node.display_name}: input '{edge.target_port}' is unavailable "
|
|
93
|
-
f"because {source.display_name} did not produce '{edge.source_port}'"
|
|
94
|
-
)
|
|
95
|
-
value = source_outputs[edge.source_port]
|
|
96
|
-
port = next(spec for spec in node.inputs if spec.name == edge.target_port)
|
|
97
|
-
if port.multiple:
|
|
98
|
-
node_inputs.setdefault(edge.target_port, []).append(value)
|
|
99
|
-
else:
|
|
100
|
-
node_inputs[edge.target_port] = value
|
|
101
|
-
|
|
102
|
-
missing = [port.name for port in node.inputs if port.required and port.name not in node_inputs]
|
|
103
|
-
if missing:
|
|
104
|
-
raise GraphExecutionError(
|
|
105
|
-
f"{node.display_name}: missing required input(s): {', '.join(missing)}"
|
|
106
|
-
)
|
|
107
|
-
return node_inputs
|
|
108
|
-
|
|
109
|
-
def complete(node_id: str, result: dict[str, Any]) -> None:
|
|
110
|
-
outputs[node_id] = result
|
|
111
|
-
order.append(node_id)
|
|
112
|
-
terminal.add(node_id)
|
|
113
|
-
for target in downstream[node_id]:
|
|
114
|
-
indegree[target] -= 1
|
|
115
|
-
if indegree[target] == 0:
|
|
116
|
-
queue.append(target)
|
|
117
|
-
|
|
118
|
-
def fail_branch(node_id: str, message: str) -> None:
|
|
119
|
-
"""Fail one node and block only nodes that depend on its output."""
|
|
120
|
-
if node_id in terminal:
|
|
121
|
-
return
|
|
122
|
-
terminal.add(node_id)
|
|
123
|
-
failures.append(message)
|
|
124
|
-
set_state(node_id, "failed")
|
|
125
|
-
emit(f"Failure: {message}")
|
|
126
|
-
pending = deque(downstream[node_id])
|
|
127
|
-
while pending:
|
|
128
|
-
blocked_id = pending.popleft()
|
|
129
|
-
if blocked_id in terminal:
|
|
130
|
-
continue
|
|
131
|
-
terminal.add(blocked_id)
|
|
132
|
-
set_state(blocked_id, "blocked")
|
|
133
|
-
emit(
|
|
134
|
-
f"Blocked {graph.nodes[blocked_id].display_name}: "
|
|
135
|
-
"an upstream dependency failed"
|
|
136
|
-
)
|
|
137
|
-
pending.extend(downstream[blocked_id])
|
|
138
|
-
|
|
139
|
-
running = {}
|
|
140
|
-
cancellation_applied = False
|
|
141
|
-
with ThreadPoolExecutor(max_workers=max_workers, thread_name_prefix="taskgraph") as pool:
|
|
142
|
-
while queue or running:
|
|
143
|
-
if cancel_event.is_set() and not cancellation_applied:
|
|
144
|
-
cancellation_applied = True
|
|
145
|
-
emit("Cancellation requested…")
|
|
146
|
-
running_ids = set(running.values())
|
|
147
|
-
for future in running:
|
|
148
|
-
future.cancel()
|
|
149
|
-
for node_id in graph.nodes:
|
|
150
|
-
if node_id not in terminal and node_id not in running_ids:
|
|
151
|
-
terminal.add(node_id)
|
|
152
|
-
set_state(node_id, "cancelled")
|
|
153
|
-
queue.clear()
|
|
154
|
-
|
|
155
|
-
while queue and len(running) < max_workers:
|
|
156
|
-
node_id = queue.popleft()
|
|
157
|
-
if node_id in terminal:
|
|
158
|
-
continue
|
|
159
|
-
node = graph.nodes[node_id]
|
|
160
|
-
if node.disabled:
|
|
161
|
-
emit(f"Skipped disabled node: {node.display_name}")
|
|
162
|
-
set_state(node_id, "skipped")
|
|
163
|
-
complete(node_id, {})
|
|
164
|
-
continue
|
|
165
|
-
try:
|
|
166
|
-
node_inputs = inputs_for(node_id)
|
|
167
|
-
except GraphExecutionError as exc:
|
|
168
|
-
fail_branch(node_id, str(exc))
|
|
169
|
-
continue
|
|
170
|
-
emit(f"Running {node.display_name}")
|
|
171
|
-
set_state(node_id, "running")
|
|
172
|
-
node._cancel_event = cancel_event
|
|
173
|
-
running[pool.submit(node.process, node_inputs)] = node_id
|
|
174
|
-
|
|
175
|
-
if not running:
|
|
176
|
-
continue
|
|
177
|
-
|
|
178
|
-
finished, _pending = wait(running, return_when=FIRST_COMPLETED)
|
|
179
|
-
for future in finished:
|
|
180
|
-
node_id = running.pop(future)
|
|
181
|
-
node = graph.nodes[node_id]
|
|
182
|
-
if cancel_event.is_set():
|
|
183
|
-
try:
|
|
184
|
-
future.result()
|
|
185
|
-
except Exception:
|
|
186
|
-
pass
|
|
187
|
-
terminal.add(node_id)
|
|
188
|
-
set_state(node_id, "cancelled")
|
|
189
|
-
emit(f"Cancelled {node.display_name}")
|
|
190
|
-
node._cancel_event = None
|
|
191
|
-
continue
|
|
192
|
-
try:
|
|
193
|
-
result = future.result()
|
|
194
|
-
except NodeCancelled:
|
|
195
|
-
terminal.add(node_id)
|
|
196
|
-
set_state(node_id, "cancelled")
|
|
197
|
-
emit(f"Cancelled {node.display_name}")
|
|
198
|
-
node._cancel_event = None
|
|
199
|
-
continue
|
|
200
|
-
except Exception as exc:
|
|
201
|
-
fail_branch(node_id, f"{node.display_name} failed: {exc}")
|
|
202
|
-
node._cancel_event = None
|
|
203
|
-
continue
|
|
204
|
-
if not isinstance(result, dict):
|
|
205
|
-
fail_branch(
|
|
206
|
-
node_id,
|
|
207
|
-
f"{node.display_name} must return a dictionary",
|
|
208
|
-
)
|
|
209
|
-
node._cancel_event = None
|
|
210
|
-
continue
|
|
211
|
-
complete(node_id, result)
|
|
212
|
-
set_state(node_id, "finished")
|
|
213
|
-
emit(f"Finished {node.display_name}: {result}")
|
|
214
|
-
node._cancel_event = None
|
|
215
|
-
|
|
216
|
-
if cancel_event.is_set():
|
|
217
|
-
# A running cooperative node may notice cancellation and finish before
|
|
218
|
-
# the scheduler reaches the next loop iteration. Ensure descendants
|
|
219
|
-
# that never entered the ready queue still receive a cancelled state.
|
|
220
|
-
for node_id in graph.nodes:
|
|
221
|
-
if node_id not in terminal:
|
|
222
|
-
terminal.add(node_id)
|
|
223
|
-
set_state(node_id, "cancelled")
|
|
224
|
-
raise GraphExecutionCancelled("Graph execution cancelled")
|
|
225
|
-
unresolved = set(graph.nodes) - terminal
|
|
226
|
-
if unresolved:
|
|
227
|
-
failures.append("The graph contains a cycle and cannot be executed")
|
|
228
|
-
for node_id in unresolved:
|
|
229
|
-
set_state(node_id, "blocked")
|
|
230
|
-
if failures:
|
|
231
|
-
raise GraphExecutionError("\n".join(failures))
|
|
232
|
-
return ExecutionResult(order, outputs)
|
{koode_taskgraph-0.1.0 → koode_taskgraph-0.3.0}/koode_taskgraph.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|