koode-taskgraph 0.2.0__tar.gz → 0.3.1__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.
- koode_taskgraph-0.3.1/PKG-INFO +234 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/README.md +13 -1
- koode_taskgraph-0.3.1/koode_taskgraph.egg-info/PKG-INFO +234 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/pyproject.toml +2 -1
- koode_taskgraph-0.3.1/taskgraph/core/executor.py +300 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/ui/properties.py +30 -2
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/tests/test_gui_plugins.py +31 -2
- koode_taskgraph-0.2.0/PKG-INFO +0 -9
- koode_taskgraph-0.2.0/koode_taskgraph.egg-info/PKG-INFO +0 -9
- koode_taskgraph-0.2.0/taskgraph/core/executor.py +0 -232
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/LICENSE +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/koode_taskgraph.egg-info/SOURCES.txt +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/koode_taskgraph.egg-info/dependency_links.txt +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/koode_taskgraph.egg-info/entry_points.txt +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/koode_taskgraph.egg-info/requires.txt +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/koode_taskgraph.egg-info/top_level.txt +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/setup.cfg +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/__init__.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/__main__.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/app.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/cli.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/core/__init__.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/core/model.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/core/registry.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/core/serialization.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/nodes/__init__.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/nodes/builtin.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/ui/__init__.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/ui/items.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/ui/main_window.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/ui/plugins.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/ui/scene.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/taskgraph/ui/theme.py +0 -0
- {koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/tests/test_core.py +0 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: koode-taskgraph
|
|
3
|
+
Version: 0.3.1
|
|
4
|
+
Summary: An extensible process node graph built with QtPy and PySide6
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: PySide6>=6.7
|
|
9
|
+
Requires-Dist: QtPy>=2.4
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
<p align="left">
|
|
13
|
+
<a href="https://buymeacoffee.com/cgarjun">
|
|
14
|
+
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="50" alt="Buy Me A Coffee">
|
|
15
|
+
</a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
# Koode TaskGraph
|
|
19
|
+
|
|
20
|
+
TaskGraph is a small, extensible process graph editor built from scratch with
|
|
21
|
+
Python, QtPy, and PySide6.
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
## Run
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
python -m venv .venv
|
|
29
|
+
source .venv/bin/activate
|
|
30
|
+
python -m pip install koode-taskgraph
|
|
31
|
+
koode-taskgraph
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For local development from this repository, use `python -m pip install -e .`.
|
|
35
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for pull request guidelines.
|
|
36
|
+
|
|
37
|
+
## Headless CLI
|
|
38
|
+
|
|
39
|
+
Execute a saved graph without starting Qt or opening a window:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
koode-taskgraph-cli --file /path/to/workflow.taskgraph
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Select the worker count and load external node locations when needed:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
koode-taskgraph-cli \
|
|
49
|
+
--file /path/to/workflow.taskgraph \
|
|
50
|
+
--workers 8 \
|
|
51
|
+
--node-path /path/to/custom_nodes
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`--node-path` may be repeated. `TASKGRAPH_NODE_PATH` is also supported with
|
|
55
|
+
the normal platform path separator. Use `--json` for structured results,
|
|
56
|
+
`--quiet` to hide progress messages, and `Ctrl+C` to cancel execution.
|
|
57
|
+
|
|
58
|
+
Exit codes are `0` for success, `1` for graph execution failure, `2` for
|
|
59
|
+
arguments/loading errors, and `130` for cancellation.
|
|
60
|
+
|
|
61
|
+
Double-click a node type in the left panel to add it. Drag from an output port
|
|
62
|
+
on the right of a node to an input port on the left of another node. Select a
|
|
63
|
+
node to edit its properties, then click **Run graph**.
|
|
64
|
+
|
|
65
|
+
## Add a node
|
|
66
|
+
|
|
67
|
+
Create a module in `taskgraph/nodes/` and define a `ProcessNode` subclass:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from taskgraph.core.model import NodeProperty, PortSpec, ProcessNode
|
|
71
|
+
from taskgraph.core.registry import register_node
|
|
72
|
+
|
|
73
|
+
@register_node
|
|
74
|
+
class PrefixText(ProcessNode):
|
|
75
|
+
type_id = "custom.prefix_text"
|
|
76
|
+
title = "Prefix Text"
|
|
77
|
+
category = "Custom"
|
|
78
|
+
inputs = (PortSpec("value", "any"),)
|
|
79
|
+
outputs = (PortSpec("text", "text"),)
|
|
80
|
+
properties = (
|
|
81
|
+
NodeProperty("prefix", "Prefix", "text", "Result: "),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
def process(self, inputs):
|
|
85
|
+
return {"text": f"{self.prefix}{inputs.get('value', '')}"}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Property kinds map to generated controls in the Properties panel: `"text"` for
|
|
89
|
+
a line edit, `"file"` for a file path field with a Browse button, `"bool"` for
|
|
90
|
+
a checkbox, `"int"`/`"float"` for numeric fields, and `"choice"` for a
|
|
91
|
+
dropdown using `choices`.
|
|
92
|
+
|
|
93
|
+
Modules in `taskgraph/nodes/` are discovered automatically. Custom modules can
|
|
94
|
+
also live anywhere on disk:
|
|
95
|
+
|
|
96
|
+
1. Put one or more standalone `.py` node modules in a directory.
|
|
97
|
+
2. Select **Nodes → Add Custom Node Location…** and choose that directory.
|
|
98
|
+
3. Restarting TaskGraph reloads the saved location automatically.
|
|
99
|
+
|
|
100
|
+
Alternatively, set `TASKGRAPH_NODE_PATH` before launching. Separate multiple
|
|
101
|
+
directories with the platform path separator (`:` on macOS/Linux and `;` on
|
|
102
|
+
Windows):
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
TASKGRAPH_NODE_PATH="/path/to/company_nodes:/path/to/my_nodes" koode-taskgraph
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Files beginning with `_` are ignored. Importing a custom node module executes
|
|
109
|
+
its Python code, so only add trusted directories. The editor, property panel,
|
|
110
|
+
serialization, and executor require no other changes.
|
|
111
|
+
|
|
112
|
+
## Add a GUI plugin
|
|
113
|
+
|
|
114
|
+
GUI plugins can add menus, actions, docks, and graph-building commands without
|
|
115
|
+
editing TaskGraph source. Put one or more `.py` files in a plugin directory and
|
|
116
|
+
define `register_taskgraph_plugin(api)`:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
def register_taskgraph_plugin(api):
|
|
120
|
+
def build_template_graph():
|
|
121
|
+
text = api.create_node(
|
|
122
|
+
"input.text",
|
|
123
|
+
name="Message",
|
|
124
|
+
values={"text": "hello world"},
|
|
125
|
+
position=(0, 0),
|
|
126
|
+
)
|
|
127
|
+
formatter = api.create_node(
|
|
128
|
+
"text.format",
|
|
129
|
+
name="Format Message",
|
|
130
|
+
values={"template": "Output: {value}"},
|
|
131
|
+
position=(280, 0),
|
|
132
|
+
)
|
|
133
|
+
printer = api.create_node(
|
|
134
|
+
"output.print",
|
|
135
|
+
name="Print Result",
|
|
136
|
+
position=(560, 0),
|
|
137
|
+
)
|
|
138
|
+
api.connect_dependency(text, formatter)
|
|
139
|
+
api.connect_attribute(text, "text", formatter, "value")
|
|
140
|
+
api.connect_dependency(formatter, printer)
|
|
141
|
+
api.connect_attribute(formatter, "text", printer, "value")
|
|
142
|
+
api.add_backdrop(
|
|
143
|
+
title="Template Notes",
|
|
144
|
+
note="This graph was created by a GUI plugin.",
|
|
145
|
+
position=(-40, -140),
|
|
146
|
+
size=(720, 180),
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
api.add_menu_action("Tools", "Build Template Graph", build_template_graph)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Load GUI plugins from **Plugins → Add GUI Plugin Location…**. Restarting
|
|
153
|
+
TaskGraph reloads saved plugin locations automatically. Alternatively, set
|
|
154
|
+
`TASKGRAPH_PLUGIN_PATH` before launching, using the same platform path
|
|
155
|
+
separator rules as `TASKGRAPH_NODE_PATH`.
|
|
156
|
+
|
|
157
|
+
This repository includes minimal example plugins in `examples/gui_plugins`.
|
|
158
|
+
Load that directory, then run **Examples → Create Hello World Print Graph** or
|
|
159
|
+
**Examples → Create Bingooo Print Graph**.
|
|
160
|
+
|
|
161
|
+
GUI plugins are intentionally separate from custom node locations. The
|
|
162
|
+
headless CLI loads `TASKGRAPH_NODE_PATH` only, so UI plugin code can safely
|
|
163
|
+
import Qt widgets without breaking `koode-taskgraph-cli`.
|
|
164
|
+
|
|
165
|
+
## Controls
|
|
166
|
+
|
|
167
|
+
- Standard commands are organized under the **File**, **Edit**, **Nodes**,
|
|
168
|
+
**Graph**, **Plugins**, and **View** menus.
|
|
169
|
+
- Drag a node from **Nodes** to the canvas, or double-click it.
|
|
170
|
+
- Every node has fixed gold **dependency** input/output ports. These control
|
|
171
|
+
process order but do not transfer values. Gold dependency connections show
|
|
172
|
+
an arrowhead pointing from the upstream node toward the downstream node.
|
|
173
|
+
- Declared node inputs and outputs are attribute ports. Attribute connections
|
|
174
|
+
transfer values, but execution order comes only from dependency connections.
|
|
175
|
+
An attribute connection therefore needs a dependency path from its source
|
|
176
|
+
node to its target node.
|
|
177
|
+
- Dependency ports connect only to dependency ports; compatible attribute
|
|
178
|
+
ports connect only to attribute ports.
|
|
179
|
+
- Select one or more nodes on the canvas and press **D** to toggle them
|
|
180
|
+
disabled. Disabled nodes stay in the dependency chain but their process
|
|
181
|
+
functions are skipped. The same command is available from **Edit**.
|
|
182
|
+
- **Copy Nodes** and **Paste Nodes** under **Edit** use the standard platform
|
|
183
|
+
shortcuts. Properties, disabled state, relative positions, and connections
|
|
184
|
+
entirely inside the copied selection are preserved.
|
|
185
|
+
- Select a node to edit generated property controls.
|
|
186
|
+
- Use **Node Name** at the top of the Properties panel to give each node
|
|
187
|
+
instance a descriptive name. Custom names appear in node headers and
|
|
188
|
+
execution messages and are preserved when saving or copying nodes.
|
|
189
|
+
- Select nodes or connections and press **Backspace** or **Delete** to remove
|
|
190
|
+
them. **Edit → Delete Selected** works on every platform too.
|
|
191
|
+
- Middle-drag pans, the mouse wheel zooms, and **F** frames the graph.
|
|
192
|
+
- **Shift+A** or **Graph → Auto Arrange Nodes** lays out dependency layers
|
|
193
|
+
from left to right and parallel nodes vertically, then frames the result.
|
|
194
|
+
- **Graph → Add Backdrop** creates a movable notes region behind the graph.
|
|
195
|
+
Select it to edit its title, notes, color, width, and height in Properties.
|
|
196
|
+
Drag the grip in its bottom-right corner to resize it interactively.
|
|
197
|
+
Backdrops are stored in `.taskgraph` files.
|
|
198
|
+
- **Ctrl+R** executes nodes in dependency order.
|
|
199
|
+
- Independent dependency branches execute concurrently. Choose between one
|
|
200
|
+
worker or any even worker count from 2 through 32 under
|
|
201
|
+
**Graph → Worker Count**; the setting is remembered.
|
|
202
|
+
- Use **Graph → Cancel Execution** or **Esc** to cancel the complete run.
|
|
203
|
+
Pending nodes are cancelled immediately. Running nodes receive a cooperative
|
|
204
|
+
cancellation signal, and built-in command nodes terminate their subprocess
|
|
205
|
+
groups promptly.
|
|
206
|
+
- Clear displayed execution messages with **Graph → Clear Execution Log** or
|
|
207
|
+
from the Execution panel's right-click menu.
|
|
208
|
+
- Built-in nodes are organized as **System → Run Command/Print**,
|
|
209
|
+
**Utils → Format Text**, and **Inputs → Text/Number**.
|
|
210
|
+
- The built-in **System → Run Command** node executes a command and exposes
|
|
211
|
+
stdout, stderr, and return code outputs. It supports an optional working
|
|
212
|
+
directory, shell mode, timeout, and failure on non-zero exit. Shell mode
|
|
213
|
+
executes exactly what the graph author enters, so only run trusted graphs.
|
|
214
|
+
- Node headers show live execution state: amber while running, green when
|
|
215
|
+
finished, red on failure, gray when a disabled node is skipped, and muted
|
|
216
|
+
red when a node is blocked by an upstream failure. Cancelled nodes use a
|
|
217
|
+
purple-gray state.
|
|
218
|
+
Execution coordination runs outside the GUI thread so the final running
|
|
219
|
+
node and parallel running nodes remain visible while work is in progress.
|
|
220
|
+
- A failed node blocks only its downstream dependency branch. Independent
|
|
221
|
+
parallel branches continue running and report their own final states.
|
|
222
|
+
- Closed panels can be restored from **View → Nodes/Properties/Execution**.
|
|
223
|
+
Use **View → Show All Panels** to restore everything at once.
|
|
224
|
+
|
|
225
|
+
Graph files use readable JSON with the `.taskgraph` extension.
|
|
226
|
+
|
|
227
|
+
## Architecture
|
|
228
|
+
|
|
229
|
+
- `core/model.py`: node contract—including inherited dependency port
|
|
230
|
+
specifications—and serializable graph model
|
|
231
|
+
- `core/registry.py`: decorator-based built-in and external node discovery
|
|
232
|
+
- `core/executor.py`: validation and dependency-ordered execution
|
|
233
|
+
- `ui/`: graphics editor, node items, property editor, and main window
|
|
234
|
+
- `nodes/`: built-in examples and the extension point for new processes
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="left">
|
|
2
|
+
<a href="https://buymeacoffee.com/cgarjun">
|
|
3
|
+
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="50" alt="Buy Me A Coffee">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
# Koode TaskGraph
|
|
2
8
|
|
|
3
9
|
TaskGraph is a small, extensible process graph editor built from scratch with
|
|
4
10
|
Python, QtPy, and PySide6.
|
|
@@ -15,6 +21,7 @@ koode-taskgraph
|
|
|
15
21
|
```
|
|
16
22
|
|
|
17
23
|
For local development from this repository, use `python -m pip install -e .`.
|
|
24
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for pull request guidelines.
|
|
18
25
|
|
|
19
26
|
## Headless CLI
|
|
20
27
|
|
|
@@ -67,6 +74,11 @@ class PrefixText(ProcessNode):
|
|
|
67
74
|
return {"text": f"{self.prefix}{inputs.get('value', '')}"}
|
|
68
75
|
```
|
|
69
76
|
|
|
77
|
+
Property kinds map to generated controls in the Properties panel: `"text"` for
|
|
78
|
+
a line edit, `"file"` for a file path field with a Browse button, `"bool"` for
|
|
79
|
+
a checkbox, `"int"`/`"float"` for numeric fields, and `"choice"` for a
|
|
80
|
+
dropdown using `choices`.
|
|
81
|
+
|
|
70
82
|
Modules in `taskgraph/nodes/` are discovered automatically. Custom modules can
|
|
71
83
|
also live anywhere on disk:
|
|
72
84
|
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: koode-taskgraph
|
|
3
|
+
Version: 0.3.1
|
|
4
|
+
Summary: An extensible process node graph built with QtPy and PySide6
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: PySide6>=6.7
|
|
9
|
+
Requires-Dist: QtPy>=2.4
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
<p align="left">
|
|
13
|
+
<a href="https://buymeacoffee.com/cgarjun">
|
|
14
|
+
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="50" alt="Buy Me A Coffee">
|
|
15
|
+
</a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
# Koode TaskGraph
|
|
19
|
+
|
|
20
|
+
TaskGraph is a small, extensible process graph editor built from scratch with
|
|
21
|
+
Python, QtPy, and PySide6.
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
## Run
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
python -m venv .venv
|
|
29
|
+
source .venv/bin/activate
|
|
30
|
+
python -m pip install koode-taskgraph
|
|
31
|
+
koode-taskgraph
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For local development from this repository, use `python -m pip install -e .`.
|
|
35
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for pull request guidelines.
|
|
36
|
+
|
|
37
|
+
## Headless CLI
|
|
38
|
+
|
|
39
|
+
Execute a saved graph without starting Qt or opening a window:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
koode-taskgraph-cli --file /path/to/workflow.taskgraph
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Select the worker count and load external node locations when needed:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
koode-taskgraph-cli \
|
|
49
|
+
--file /path/to/workflow.taskgraph \
|
|
50
|
+
--workers 8 \
|
|
51
|
+
--node-path /path/to/custom_nodes
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`--node-path` may be repeated. `TASKGRAPH_NODE_PATH` is also supported with
|
|
55
|
+
the normal platform path separator. Use `--json` for structured results,
|
|
56
|
+
`--quiet` to hide progress messages, and `Ctrl+C` to cancel execution.
|
|
57
|
+
|
|
58
|
+
Exit codes are `0` for success, `1` for graph execution failure, `2` for
|
|
59
|
+
arguments/loading errors, and `130` for cancellation.
|
|
60
|
+
|
|
61
|
+
Double-click a node type in the left panel to add it. Drag from an output port
|
|
62
|
+
on the right of a node to an input port on the left of another node. Select a
|
|
63
|
+
node to edit its properties, then click **Run graph**.
|
|
64
|
+
|
|
65
|
+
## Add a node
|
|
66
|
+
|
|
67
|
+
Create a module in `taskgraph/nodes/` and define a `ProcessNode` subclass:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from taskgraph.core.model import NodeProperty, PortSpec, ProcessNode
|
|
71
|
+
from taskgraph.core.registry import register_node
|
|
72
|
+
|
|
73
|
+
@register_node
|
|
74
|
+
class PrefixText(ProcessNode):
|
|
75
|
+
type_id = "custom.prefix_text"
|
|
76
|
+
title = "Prefix Text"
|
|
77
|
+
category = "Custom"
|
|
78
|
+
inputs = (PortSpec("value", "any"),)
|
|
79
|
+
outputs = (PortSpec("text", "text"),)
|
|
80
|
+
properties = (
|
|
81
|
+
NodeProperty("prefix", "Prefix", "text", "Result: "),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
def process(self, inputs):
|
|
85
|
+
return {"text": f"{self.prefix}{inputs.get('value', '')}"}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Property kinds map to generated controls in the Properties panel: `"text"` for
|
|
89
|
+
a line edit, `"file"` for a file path field with a Browse button, `"bool"` for
|
|
90
|
+
a checkbox, `"int"`/`"float"` for numeric fields, and `"choice"` for a
|
|
91
|
+
dropdown using `choices`.
|
|
92
|
+
|
|
93
|
+
Modules in `taskgraph/nodes/` are discovered automatically. Custom modules can
|
|
94
|
+
also live anywhere on disk:
|
|
95
|
+
|
|
96
|
+
1. Put one or more standalone `.py` node modules in a directory.
|
|
97
|
+
2. Select **Nodes → Add Custom Node Location…** and choose that directory.
|
|
98
|
+
3. Restarting TaskGraph reloads the saved location automatically.
|
|
99
|
+
|
|
100
|
+
Alternatively, set `TASKGRAPH_NODE_PATH` before launching. Separate multiple
|
|
101
|
+
directories with the platform path separator (`:` on macOS/Linux and `;` on
|
|
102
|
+
Windows):
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
TASKGRAPH_NODE_PATH="/path/to/company_nodes:/path/to/my_nodes" koode-taskgraph
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Files beginning with `_` are ignored. Importing a custom node module executes
|
|
109
|
+
its Python code, so only add trusted directories. The editor, property panel,
|
|
110
|
+
serialization, and executor require no other changes.
|
|
111
|
+
|
|
112
|
+
## Add a GUI plugin
|
|
113
|
+
|
|
114
|
+
GUI plugins can add menus, actions, docks, and graph-building commands without
|
|
115
|
+
editing TaskGraph source. Put one or more `.py` files in a plugin directory and
|
|
116
|
+
define `register_taskgraph_plugin(api)`:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
def register_taskgraph_plugin(api):
|
|
120
|
+
def build_template_graph():
|
|
121
|
+
text = api.create_node(
|
|
122
|
+
"input.text",
|
|
123
|
+
name="Message",
|
|
124
|
+
values={"text": "hello world"},
|
|
125
|
+
position=(0, 0),
|
|
126
|
+
)
|
|
127
|
+
formatter = api.create_node(
|
|
128
|
+
"text.format",
|
|
129
|
+
name="Format Message",
|
|
130
|
+
values={"template": "Output: {value}"},
|
|
131
|
+
position=(280, 0),
|
|
132
|
+
)
|
|
133
|
+
printer = api.create_node(
|
|
134
|
+
"output.print",
|
|
135
|
+
name="Print Result",
|
|
136
|
+
position=(560, 0),
|
|
137
|
+
)
|
|
138
|
+
api.connect_dependency(text, formatter)
|
|
139
|
+
api.connect_attribute(text, "text", formatter, "value")
|
|
140
|
+
api.connect_dependency(formatter, printer)
|
|
141
|
+
api.connect_attribute(formatter, "text", printer, "value")
|
|
142
|
+
api.add_backdrop(
|
|
143
|
+
title="Template Notes",
|
|
144
|
+
note="This graph was created by a GUI plugin.",
|
|
145
|
+
position=(-40, -140),
|
|
146
|
+
size=(720, 180),
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
api.add_menu_action("Tools", "Build Template Graph", build_template_graph)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Load GUI plugins from **Plugins → Add GUI Plugin Location…**. Restarting
|
|
153
|
+
TaskGraph reloads saved plugin locations automatically. Alternatively, set
|
|
154
|
+
`TASKGRAPH_PLUGIN_PATH` before launching, using the same platform path
|
|
155
|
+
separator rules as `TASKGRAPH_NODE_PATH`.
|
|
156
|
+
|
|
157
|
+
This repository includes minimal example plugins in `examples/gui_plugins`.
|
|
158
|
+
Load that directory, then run **Examples → Create Hello World Print Graph** or
|
|
159
|
+
**Examples → Create Bingooo Print Graph**.
|
|
160
|
+
|
|
161
|
+
GUI plugins are intentionally separate from custom node locations. The
|
|
162
|
+
headless CLI loads `TASKGRAPH_NODE_PATH` only, so UI plugin code can safely
|
|
163
|
+
import Qt widgets without breaking `koode-taskgraph-cli`.
|
|
164
|
+
|
|
165
|
+
## Controls
|
|
166
|
+
|
|
167
|
+
- Standard commands are organized under the **File**, **Edit**, **Nodes**,
|
|
168
|
+
**Graph**, **Plugins**, and **View** menus.
|
|
169
|
+
- Drag a node from **Nodes** to the canvas, or double-click it.
|
|
170
|
+
- Every node has fixed gold **dependency** input/output ports. These control
|
|
171
|
+
process order but do not transfer values. Gold dependency connections show
|
|
172
|
+
an arrowhead pointing from the upstream node toward the downstream node.
|
|
173
|
+
- Declared node inputs and outputs are attribute ports. Attribute connections
|
|
174
|
+
transfer values, but execution order comes only from dependency connections.
|
|
175
|
+
An attribute connection therefore needs a dependency path from its source
|
|
176
|
+
node to its target node.
|
|
177
|
+
- Dependency ports connect only to dependency ports; compatible attribute
|
|
178
|
+
ports connect only to attribute ports.
|
|
179
|
+
- Select one or more nodes on the canvas and press **D** to toggle them
|
|
180
|
+
disabled. Disabled nodes stay in the dependency chain but their process
|
|
181
|
+
functions are skipped. The same command is available from **Edit**.
|
|
182
|
+
- **Copy Nodes** and **Paste Nodes** under **Edit** use the standard platform
|
|
183
|
+
shortcuts. Properties, disabled state, relative positions, and connections
|
|
184
|
+
entirely inside the copied selection are preserved.
|
|
185
|
+
- Select a node to edit generated property controls.
|
|
186
|
+
- Use **Node Name** at the top of the Properties panel to give each node
|
|
187
|
+
instance a descriptive name. Custom names appear in node headers and
|
|
188
|
+
execution messages and are preserved when saving or copying nodes.
|
|
189
|
+
- Select nodes or connections and press **Backspace** or **Delete** to remove
|
|
190
|
+
them. **Edit → Delete Selected** works on every platform too.
|
|
191
|
+
- Middle-drag pans, the mouse wheel zooms, and **F** frames the graph.
|
|
192
|
+
- **Shift+A** or **Graph → Auto Arrange Nodes** lays out dependency layers
|
|
193
|
+
from left to right and parallel nodes vertically, then frames the result.
|
|
194
|
+
- **Graph → Add Backdrop** creates a movable notes region behind the graph.
|
|
195
|
+
Select it to edit its title, notes, color, width, and height in Properties.
|
|
196
|
+
Drag the grip in its bottom-right corner to resize it interactively.
|
|
197
|
+
Backdrops are stored in `.taskgraph` files.
|
|
198
|
+
- **Ctrl+R** executes nodes in dependency order.
|
|
199
|
+
- Independent dependency branches execute concurrently. Choose between one
|
|
200
|
+
worker or any even worker count from 2 through 32 under
|
|
201
|
+
**Graph → Worker Count**; the setting is remembered.
|
|
202
|
+
- Use **Graph → Cancel Execution** or **Esc** to cancel the complete run.
|
|
203
|
+
Pending nodes are cancelled immediately. Running nodes receive a cooperative
|
|
204
|
+
cancellation signal, and built-in command nodes terminate their subprocess
|
|
205
|
+
groups promptly.
|
|
206
|
+
- Clear displayed execution messages with **Graph → Clear Execution Log** or
|
|
207
|
+
from the Execution panel's right-click menu.
|
|
208
|
+
- Built-in nodes are organized as **System → Run Command/Print**,
|
|
209
|
+
**Utils → Format Text**, and **Inputs → Text/Number**.
|
|
210
|
+
- The built-in **System → Run Command** node executes a command and exposes
|
|
211
|
+
stdout, stderr, and return code outputs. It supports an optional working
|
|
212
|
+
directory, shell mode, timeout, and failure on non-zero exit. Shell mode
|
|
213
|
+
executes exactly what the graph author enters, so only run trusted graphs.
|
|
214
|
+
- Node headers show live execution state: amber while running, green when
|
|
215
|
+
finished, red on failure, gray when a disabled node is skipped, and muted
|
|
216
|
+
red when a node is blocked by an upstream failure. Cancelled nodes use a
|
|
217
|
+
purple-gray state.
|
|
218
|
+
Execution coordination runs outside the GUI thread so the final running
|
|
219
|
+
node and parallel running nodes remain visible while work is in progress.
|
|
220
|
+
- A failed node blocks only its downstream dependency branch. Independent
|
|
221
|
+
parallel branches continue running and report their own final states.
|
|
222
|
+
- Closed panels can be restored from **View → Nodes/Properties/Execution**.
|
|
223
|
+
Use **View → Show All Panels** to restore everything at once.
|
|
224
|
+
|
|
225
|
+
Graph files use readable JSON with the `.taskgraph` extension.
|
|
226
|
+
|
|
227
|
+
## Architecture
|
|
228
|
+
|
|
229
|
+
- `core/model.py`: node contract—including inherited dependency port
|
|
230
|
+
specifications—and serializable graph model
|
|
231
|
+
- `core/registry.py`: decorator-based built-in and external node discovery
|
|
232
|
+
- `core/executor.py`: validation and dependency-ordered execution
|
|
233
|
+
- `ui/`: graphics editor, node items, property editor, and main window
|
|
234
|
+
- `nodes/`: built-in examples and the extension point for new processes
|
|
@@ -4,7 +4,8 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "koode-taskgraph"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.1"
|
|
8
|
+
readme = "README.md"
|
|
8
9
|
description = "An extensible process node graph built with QtPy and PySide6"
|
|
9
10
|
requires-python = ">=3.10"
|
|
10
11
|
dependencies = [
|
|
@@ -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,11 +5,12 @@ 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
|
|
11
|
+
from taskgraph.core.model import Graph, NodeProperty, ProcessNode
|
|
12
12
|
from taskgraph.ui.main_window import MainWindow
|
|
13
|
+
from taskgraph.ui.properties import PropertyEditor
|
|
13
14
|
from taskgraph.ui.plugins import load_gui_plugin_directory
|
|
14
15
|
|
|
15
16
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
@@ -126,5 +127,33 @@ class GuiPluginTests(unittest.TestCase):
|
|
|
126
127
|
)
|
|
127
128
|
|
|
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
|
+
|
|
157
|
+
|
|
129
158
|
if __name__ == "__main__":
|
|
130
159
|
unittest.main()
|
koode_taskgraph-0.2.0/PKG-INFO
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: koode-taskgraph
|
|
3
|
-
Version: 0.2.0
|
|
4
|
-
Summary: An extensible process node graph built with QtPy and PySide6
|
|
5
|
-
Requires-Python: >=3.10
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Requires-Dist: PySide6>=6.7
|
|
8
|
-
Requires-Dist: QtPy>=2.4
|
|
9
|
-
Dynamic: license-file
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: koode-taskgraph
|
|
3
|
-
Version: 0.2.0
|
|
4
|
-
Summary: An extensible process node graph built with QtPy and PySide6
|
|
5
|
-
Requires-Python: >=3.10
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Requires-Dist: PySide6>=6.7
|
|
8
|
-
Requires-Dist: QtPy>=2.4
|
|
9
|
-
Dynamic: license-file
|
|
@@ -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)
|
|
File without changes
|
|
File without changes
|
{koode_taskgraph-0.2.0 → koode_taskgraph-0.3.1}/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
|
|
File without changes
|
|
File without changes
|