flowgraph 0.1.8__tar.gz → 0.1.9__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.
- {flowgraph-0.1.8/src/flowgraph.egg-info → flowgraph-0.1.9}/PKG-INFO +65 -4
- {flowgraph-0.1.8 → flowgraph-0.1.9}/README.md +60 -2
- {flowgraph-0.1.8 → flowgraph-0.1.9}/pyproject.toml +5 -3
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/__init__.py +8 -1
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/data_types.py +1 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/field_ops.py +1 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/files.py +60 -9
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/filters.py +1 -12
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/image_tools.py +44 -1
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/imagej.py +87 -6
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/mesh_analysis.py +32 -8
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/mesh_creation_tools.py +2 -2
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/mesh_ops.py +2 -2
- flowgraph-0.1.9/src/flowgraph/adapters/sinks.py +208 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/user_code.py +77 -2
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/workflow.py +2 -0
- flowgraph-0.1.9/src/flowgraph/application/node_registry.py +28 -0
- flowgraph-0.1.9/src/flowgraph/application/plugins.py +60 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/port_conversions.py +2 -0
- flowgraph-0.1.9/src/flowgraph/application/wasm_packages.py +245 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/workflow_cli.py +68 -13
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/workflow_core.py +147 -95
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/workflow_defaults.py +11 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/workflow_execution.py +97 -8
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/workflow_io.py +6 -3
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/workflow_session.py +36 -5
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/core_cli.py +64 -4
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/paraview_gateway.py +26 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/server/http.py +156 -11
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/server/jobs.py +153 -26
- flowgraph-0.1.9/src/flowgraph/server/packages.py +233 -0
- flowgraph-0.1.9/src/flowgraph/server/worker.py +81 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/server/workspace.py +7 -1
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/testdata/AllFilters.json +3 -3
- flowgraph-0.1.9/src/flowgraph/testdata/ImageJBlur.json +249 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/testdata/SimpleReadMesh.json +3 -3
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/version.py +1 -1
- {flowgraph-0.1.8 → flowgraph-0.1.9/src/flowgraph.egg-info}/PKG-INFO +65 -4
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph.egg-info/SOURCES.txt +10 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph.egg-info/requires.txt +5 -1
- flowgraph-0.1.9/tests/test_image_roi.py +95 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_image_tools.py +96 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_imagej.py +217 -1
- flowgraph-0.1.9/tests/test_local_server.py +1044 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_mesh_analysis.py +107 -7
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_mesh_ops.py +9 -5
- flowgraph-0.1.9/tests/test_native_packages.py +180 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_node_selector.py +2 -60
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_packaging.py +51 -5
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_paraview.py +54 -0
- flowgraph-0.1.9/tests/test_plugins.py +279 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_readers.py +24 -3
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_release.py +73 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_sinks.py +8 -2
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_transfer_fields.py +23 -2
- flowgraph-0.1.9/tests/test_user_function_parameters.py +127 -0
- flowgraph-0.1.9/tests/test_wasm_packages.py +148 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_workflow_cli.py +120 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_workflow_execution.py +159 -2
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_workflow_io.py +43 -1
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_workflow_web_catalog.py +23 -2
- flowgraph-0.1.9/tests/test_workspace_file.py +254 -0
- flowgraph-0.1.8/src/flowgraph/adapters/sinks.py +0 -111
- flowgraph-0.1.8/src/flowgraph/application/node_registry.py +0 -14
- flowgraph-0.1.8/src/flowgraph/server/worker.py +0 -36
- flowgraph-0.1.8/tests/test_local_server.py +0 -536
- {flowgraph-0.1.8 → flowgraph-0.1.9}/LICENSE +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/setup.cfg +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/__init__.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/__main__.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/calculator.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/controls.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/cosapp.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/documentation.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/field_gradient.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/file_conversion.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/mesh_composition.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/mesh_generations.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/paraview.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/plaid_bridge.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/readers.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/remote_files.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/simple_sources.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/table_tools.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/vector_tools.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/workflow_interfaces.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/writers.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/adapters/zones.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/__init__.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/file_dependencies.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/workflow_history.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/workflow_layout.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/workflow_web_catalog.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/application/workflows.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/domain/__init__.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/domain/filepath.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/domain/mesh_document.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/examples/AllFilters.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/examples/convert_format.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/resources.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/server/__init__.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/testdata/ColorCardboard.jpg +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/testdata/FlowGraph.h5 +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/testdata/FlowGraph.stl +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/testdata/FlowGraph.xdmf +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/testdata/SpherePoints.csv +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph/testdata/muscat-muscat-mesh-conversion.json +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph.egg-info/dependency_links.txt +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph.egg-info/entry_points.txt +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/src/flowgraph.egg-info/top_level.txt +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_array_nodes.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_array_types.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_audit_requirements.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_cache_policy.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_calculator.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_conditional_workflow.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_controls.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_core_gui_boundary.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_cosapp.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_directory_dependencies.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_extract_field.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_extract_vector_value.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_field_gradient.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_file_conversion.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_filepath.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_fluency_optimization.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_headless_boundary.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_mesh_composition.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_mesh_creation_tools.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_muscat_vtk.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_plaid_bridge.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_remote_files.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_remove_lonely_nodes.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_scalars_to_array_1d.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_simple_sources.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_table_tools.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_user_code_mesh.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_vector_field_gradient.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_vector_tools.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_workflow_core.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_workflow_history.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_workflow_session.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_workspace_directories.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_writers.py +0 -0
- {flowgraph-0.1.8 → flowgraph-0.1.9}/tests/test_zones.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flowgraph
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.9
|
|
4
4
|
Summary: Headless typed workflow engine and execution runtime
|
|
5
5
|
Author: Felipe Bordeu
|
|
6
6
|
Maintainer: Felipe Bordeu
|
|
@@ -24,8 +24,11 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
24
24
|
Requires-Python: >=3.11
|
|
25
25
|
Description-Content-Type: text/markdown
|
|
26
26
|
License-File: LICENSE
|
|
27
|
+
Requires-Dist: packaging>=24
|
|
27
28
|
Requires-Dist: vtk>=9.2
|
|
28
|
-
Requires-Dist: muscat>=2.
|
|
29
|
+
Requires-Dist: muscat>=2.6.0
|
|
30
|
+
Provides-Extra: server
|
|
31
|
+
Requires-Dist: uv>=0.6; extra == "server"
|
|
29
32
|
Provides-Extra: io
|
|
30
33
|
Requires-Dist: meshio>=5.3; extra == "io"
|
|
31
34
|
Requires-Dist: meshlane>=5.5.0; extra == "io"
|
|
@@ -91,10 +94,27 @@ uv run flowgraph run workflow.json --input name=value
|
|
|
91
94
|
uv run flowgraph run workflow.json -i name=value
|
|
92
95
|
uv run flowgraph run workflow.json --override node-id.parameter=value
|
|
93
96
|
uv run flowgraph run workflow.json --json-output results.json
|
|
97
|
+
uv run flowgraph run workflow.json --verbose
|
|
98
|
+
uv run flowgraph run workflow.json --plugin /path/custom_nodes.py
|
|
99
|
+
uv run flowgraph inspect workflow.json --plugin /path/custom_nodes.py --full
|
|
94
100
|
```
|
|
95
101
|
|
|
102
|
+
Use repeatable `--plugin FILE.py` to load trusted custom definitions exported as
|
|
103
|
+
`AVAILABLE_NODES`. The same option on `flowgraph serve` adds nodes to its catalog
|
|
104
|
+
and execution workers. Imports execute Python code, including during inspection;
|
|
105
|
+
only load trusted files. See the [plugin guide](doc/user-guide/custom-nodes.md#load-python-file-plugins-from-the-cli-or-server)
|
|
106
|
+
for the file format, path rules, dependencies and restart requirements.
|
|
107
|
+
|
|
96
108
|
Use `--input` or its short form `-i` for each published workflow input; repeat
|
|
97
109
|
the option to provide multiple inputs.
|
|
110
|
+
|
|
111
|
+
Add `--verbose` (or `-v`) to `run` for execution states and live, bounded node
|
|
112
|
+
output-port summaries on stderr, matching `serve` diagnostics. Node stdout/stderr
|
|
113
|
+
remain visible and Python console output is line-buffered in verbose mode.
|
|
114
|
+
Summaries use runtime values without making copies or generating previews.
|
|
115
|
+
Verbose logs may contain sensitive workflow data; keep them private.
|
|
116
|
+
Final outputs and `--json-output` retain their normal behavior.
|
|
117
|
+
|
|
98
118
|
`flowgraph inspect` displays the resolved default to the right of each published
|
|
99
119
|
input, or marks it as required or having conflicting saved values.
|
|
100
120
|
Inspection is compact by default; add `--full` (or `-f`) to include the workflow
|
|
@@ -141,12 +161,49 @@ together; the workflow file and execution response formats are unchanged.
|
|
|
141
161
|
|
|
142
162
|
## Experimental local server
|
|
143
163
|
|
|
144
|
-
|
|
164
|
+
### Optional workspace packages
|
|
165
|
+
|
|
166
|
+
Install the `server` extra (`uv sync --extra server`, or install `flowgraph[server]`)
|
|
167
|
+
and pass `--allow-package-install` to `flowgraph serve` to enable the web editor's
|
|
168
|
+
confirmed wheel-only installation API. It is disabled by default. Compatible
|
|
169
|
+
prebuilt Python/native wheels are installed with uv into
|
|
170
|
+
`<workspace>/.flowgraph-packages/<python-and-platform-id>/site-packages`, not the
|
|
171
|
+
base environment. Extras persist across server restarts. Stop the backend and
|
|
172
|
+
delete `.flowgraph-packages` to remove them. Read-only workspace destinations,
|
|
173
|
+
source builds, conflicting distributions and base-module shadowing are rejected.
|
|
174
|
+
Installation requires idle execution and restarts session workers, clearing caches.
|
|
175
|
+
The managed directory is excluded from the file API. Only install trusted code;
|
|
176
|
+
this is not a sandbox or a multi-user package service.
|
|
177
|
+
|
|
178
|
+
The prototype branch includes an authenticated execution API (loopback by default):
|
|
179
|
+
|
|
180
|
+
For LAN or internet browser clients, put an HTTPS reverse proxy in front of the
|
|
181
|
+
API and pass `--public-url https://python.example.com` to `flowgraph serve`.
|
|
182
|
+
The proxy must preserve the public Host header, Authorization, Origin, and CORS
|
|
183
|
+
preflight headers. Leave Python on `127.0.0.1:8765` when the proxy runs on the
|
|
184
|
+
same machine. An explicit IPv4 `--host` (including `0.0.0.0`) is supported but
|
|
185
|
+
non-loopback binding requires `--public-url`; restrict the HTTP port to a trusted
|
|
186
|
+
proxy network. This option advertises HTTPS; it does not enable TLS in Python.
|
|
187
|
+
Certificates must be trusted by browser clients, including for private LAN IPs.
|
|
188
|
+
Use `--allow-origin` to allow your exact editor origin (the hosted editor is the
|
|
189
|
+
default). The launch link includes the remote backend address in its fragment.
|
|
190
|
+
This is a trusted single-user service, not a sandbox or a public multi-user API;
|
|
191
|
+
use an unprivileged account, firewall/VPN restrictions, and proxy request limits.
|
|
145
192
|
|
|
146
193
|
```bash
|
|
147
194
|
uv run flowgraph serve --workspace /absolute/path/to/existing/workspace
|
|
148
195
|
```
|
|
149
196
|
|
|
197
|
+
Add `--verbose` (or `-v`) for server lifecycle, configuration, sanitized HTTP
|
|
198
|
+
activity, execution state changes, and bounded node output-port summaries on
|
|
199
|
+
stderr. Worker stdout/stderr (prints and logs) also appear in the console.
|
|
200
|
+
Verbose logs may contain sensitive workflow data; keep them private.
|
|
201
|
+
For an isolated tool launch:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
uvx --with imagej flowgraph serve --workspace . --verbose
|
|
205
|
+
```
|
|
206
|
+
|
|
150
207
|
Port 8765 and the allowed editor origin `https://flowgraph-web.fbw-es.com` are
|
|
151
208
|
defaults; explicit `--allow-origin` values replace that origin. The editor still
|
|
152
209
|
requires bearer authentication and browser local-network permission. Click the
|
|
@@ -154,7 +211,11 @@ printed **Open editor** link to pass the token and port automatically; keep the
|
|
|
154
211
|
link private.
|
|
155
212
|
|
|
156
213
|
It runs one workflow at a time in a cancellable native subprocess and provides
|
|
157
|
-
runtime metadata, catalog, and workspace file endpoints.
|
|
214
|
+
runtime metadata, catalog, and workspace file endpoints. Execution timeouts are
|
|
215
|
+
advisory: the worker remains alive until completion or explicit cancellation,
|
|
216
|
+
and the HTTP server is not stopped. GUI clients can supply a per-job timeout;
|
|
217
|
+
`--execution-timeout` sets the default warning threshold (120 seconds).
|
|
218
|
+
Core is API-only and never
|
|
158
219
|
serves editor assets. Web and desktop clients own their GUI hosting and explicitly
|
|
159
220
|
allow their origin with `--allow-origin`. Native workflow code is **not sandboxed**.
|
|
160
221
|
See [Local server API and limitations](docs/local-server.md) for authentication,
|
|
@@ -39,10 +39,27 @@ uv run flowgraph run workflow.json --input name=value
|
|
|
39
39
|
uv run flowgraph run workflow.json -i name=value
|
|
40
40
|
uv run flowgraph run workflow.json --override node-id.parameter=value
|
|
41
41
|
uv run flowgraph run workflow.json --json-output results.json
|
|
42
|
+
uv run flowgraph run workflow.json --verbose
|
|
43
|
+
uv run flowgraph run workflow.json --plugin /path/custom_nodes.py
|
|
44
|
+
uv run flowgraph inspect workflow.json --plugin /path/custom_nodes.py --full
|
|
42
45
|
```
|
|
43
46
|
|
|
47
|
+
Use repeatable `--plugin FILE.py` to load trusted custom definitions exported as
|
|
48
|
+
`AVAILABLE_NODES`. The same option on `flowgraph serve` adds nodes to its catalog
|
|
49
|
+
and execution workers. Imports execute Python code, including during inspection;
|
|
50
|
+
only load trusted files. See the [plugin guide](doc/user-guide/custom-nodes.md#load-python-file-plugins-from-the-cli-or-server)
|
|
51
|
+
for the file format, path rules, dependencies and restart requirements.
|
|
52
|
+
|
|
44
53
|
Use `--input` or its short form `-i` for each published workflow input; repeat
|
|
45
54
|
the option to provide multiple inputs.
|
|
55
|
+
|
|
56
|
+
Add `--verbose` (or `-v`) to `run` for execution states and live, bounded node
|
|
57
|
+
output-port summaries on stderr, matching `serve` diagnostics. Node stdout/stderr
|
|
58
|
+
remain visible and Python console output is line-buffered in verbose mode.
|
|
59
|
+
Summaries use runtime values without making copies or generating previews.
|
|
60
|
+
Verbose logs may contain sensitive workflow data; keep them private.
|
|
61
|
+
Final outputs and `--json-output` retain their normal behavior.
|
|
62
|
+
|
|
46
63
|
`flowgraph inspect` displays the resolved default to the right of each published
|
|
47
64
|
input, or marks it as required or having conflicting saved values.
|
|
48
65
|
Inspection is compact by default; add `--full` (or `-f`) to include the workflow
|
|
@@ -89,12 +106,49 @@ together; the workflow file and execution response formats are unchanged.
|
|
|
89
106
|
|
|
90
107
|
## Experimental local server
|
|
91
108
|
|
|
92
|
-
|
|
109
|
+
### Optional workspace packages
|
|
110
|
+
|
|
111
|
+
Install the `server` extra (`uv sync --extra server`, or install `flowgraph[server]`)
|
|
112
|
+
and pass `--allow-package-install` to `flowgraph serve` to enable the web editor's
|
|
113
|
+
confirmed wheel-only installation API. It is disabled by default. Compatible
|
|
114
|
+
prebuilt Python/native wheels are installed with uv into
|
|
115
|
+
`<workspace>/.flowgraph-packages/<python-and-platform-id>/site-packages`, not the
|
|
116
|
+
base environment. Extras persist across server restarts. Stop the backend and
|
|
117
|
+
delete `.flowgraph-packages` to remove them. Read-only workspace destinations,
|
|
118
|
+
source builds, conflicting distributions and base-module shadowing are rejected.
|
|
119
|
+
Installation requires idle execution and restarts session workers, clearing caches.
|
|
120
|
+
The managed directory is excluded from the file API. Only install trusted code;
|
|
121
|
+
this is not a sandbox or a multi-user package service.
|
|
122
|
+
|
|
123
|
+
The prototype branch includes an authenticated execution API (loopback by default):
|
|
124
|
+
|
|
125
|
+
For LAN or internet browser clients, put an HTTPS reverse proxy in front of the
|
|
126
|
+
API and pass `--public-url https://python.example.com` to `flowgraph serve`.
|
|
127
|
+
The proxy must preserve the public Host header, Authorization, Origin, and CORS
|
|
128
|
+
preflight headers. Leave Python on `127.0.0.1:8765` when the proxy runs on the
|
|
129
|
+
same machine. An explicit IPv4 `--host` (including `0.0.0.0`) is supported but
|
|
130
|
+
non-loopback binding requires `--public-url`; restrict the HTTP port to a trusted
|
|
131
|
+
proxy network. This option advertises HTTPS; it does not enable TLS in Python.
|
|
132
|
+
Certificates must be trusted by browser clients, including for private LAN IPs.
|
|
133
|
+
Use `--allow-origin` to allow your exact editor origin (the hosted editor is the
|
|
134
|
+
default). The launch link includes the remote backend address in its fragment.
|
|
135
|
+
This is a trusted single-user service, not a sandbox or a public multi-user API;
|
|
136
|
+
use an unprivileged account, firewall/VPN restrictions, and proxy request limits.
|
|
93
137
|
|
|
94
138
|
```bash
|
|
95
139
|
uv run flowgraph serve --workspace /absolute/path/to/existing/workspace
|
|
96
140
|
```
|
|
97
141
|
|
|
142
|
+
Add `--verbose` (or `-v`) for server lifecycle, configuration, sanitized HTTP
|
|
143
|
+
activity, execution state changes, and bounded node output-port summaries on
|
|
144
|
+
stderr. Worker stdout/stderr (prints and logs) also appear in the console.
|
|
145
|
+
Verbose logs may contain sensitive workflow data; keep them private.
|
|
146
|
+
For an isolated tool launch:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
uvx --with imagej flowgraph serve --workspace . --verbose
|
|
150
|
+
```
|
|
151
|
+
|
|
98
152
|
Port 8765 and the allowed editor origin `https://flowgraph-web.fbw-es.com` are
|
|
99
153
|
defaults; explicit `--allow-origin` values replace that origin. The editor still
|
|
100
154
|
requires bearer authentication and browser local-network permission. Click the
|
|
@@ -102,7 +156,11 @@ printed **Open editor** link to pass the token and port automatically; keep the
|
|
|
102
156
|
link private.
|
|
103
157
|
|
|
104
158
|
It runs one workflow at a time in a cancellable native subprocess and provides
|
|
105
|
-
runtime metadata, catalog, and workspace file endpoints.
|
|
159
|
+
runtime metadata, catalog, and workspace file endpoints. Execution timeouts are
|
|
160
|
+
advisory: the worker remains alive until completion or explicit cancellation,
|
|
161
|
+
and the HTTP server is not stopped. GUI clients can supply a per-job timeout;
|
|
162
|
+
`--execution-timeout` sets the default warning threshold (120 seconds).
|
|
163
|
+
Core is API-only and never
|
|
106
164
|
serves editor assets. Web and desktop clients own their GUI hosting and explicitly
|
|
107
165
|
allow their origin with `--allow-origin`. Native workflow code is **not sandboxed**.
|
|
108
166
|
See [Local server API and limitations](docs/local-server.md) for authentication,
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "flowgraph"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.9"
|
|
8
8
|
description = "Headless typed workflow engine and execution runtime"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -27,11 +27,13 @@ classifiers = [
|
|
|
27
27
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
28
|
]
|
|
29
29
|
dependencies = [
|
|
30
|
+
"packaging>=24",
|
|
30
31
|
"vtk>=9.2",
|
|
31
|
-
"muscat>=2.
|
|
32
|
+
"muscat>=2.6.0",
|
|
32
33
|
]
|
|
33
34
|
|
|
34
35
|
[project.optional-dependencies]
|
|
36
|
+
server = ["uv>=0.6"]
|
|
35
37
|
io = [
|
|
36
38
|
"meshio>=5.3",
|
|
37
39
|
"meshlane>=5.5.0",
|
|
@@ -87,4 +89,4 @@ pythonpath = [".", "src"]
|
|
|
87
89
|
|
|
88
90
|
[tool.ruff]
|
|
89
91
|
target-version = "py311"
|
|
90
|
-
line-length = 100
|
|
92
|
+
line-length = 100
|
|
@@ -12,6 +12,7 @@ from flowgraph.adapters.files import (
|
|
|
12
12
|
READ_DIRECTORY_FILES,
|
|
13
13
|
SELECT_FILE,
|
|
14
14
|
SELECT_SERVER_FILE,
|
|
15
|
+
WORKSPACE,
|
|
15
16
|
)
|
|
16
17
|
from flowgraph.adapters.filters import (
|
|
17
18
|
CREATE_MUSCAT_ELEMENT_FILTER,
|
|
@@ -117,7 +118,13 @@ ADAPTERS = AdapterCatalog(
|
|
|
117
118
|
),
|
|
118
119
|
AdapterGroup(
|
|
119
120
|
"Files",
|
|
120
|
-
(
|
|
121
|
+
(
|
|
122
|
+
SELECT_FILE,
|
|
123
|
+
SELECT_SERVER_FILE,
|
|
124
|
+
WORKSPACE,
|
|
125
|
+
DOWNLOAD_URL,
|
|
126
|
+
READ_DIRECTORY_FILES,
|
|
127
|
+
),
|
|
121
128
|
),
|
|
122
129
|
),
|
|
123
130
|
),
|
|
@@ -109,6 +109,7 @@ TRANSFER_FIELDS_NODE = NodeDefinition(
|
|
|
109
109
|
"Interpolation",
|
|
110
110
|
"Interp/Clamp",
|
|
111
111
|
options=(
|
|
112
|
+
ParameterOption("Nearest/Nearest", "Nearest point"),
|
|
112
113
|
ParameterOption("Interp/Clamp", "Interpolation / Clamp"),
|
|
113
114
|
ParameterOption("Interp/Nearest", "Interpolation / Nearest"),
|
|
114
115
|
ParameterOption("Interp/Extrap", "Interpolation / Extrapolation"),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import re
|
|
4
4
|
from collections.abc import Mapping
|
|
5
|
-
from pathlib import Path
|
|
5
|
+
from pathlib import Path, PureWindowsPath
|
|
6
6
|
from typing import Any
|
|
7
7
|
|
|
8
8
|
from flowgraph.application.workflow_core import (
|
|
@@ -13,7 +13,7 @@ from flowgraph.application.workflow_core import (
|
|
|
13
13
|
PortDirection,
|
|
14
14
|
)
|
|
15
15
|
|
|
16
|
-
from .data_types import LIST_STR, STRING, ParameterKind
|
|
16
|
+
from .data_types import DIRECTORY, LIST_STR, STRING, ParameterKind
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def _select_file(
|
|
@@ -57,27 +57,39 @@ def _select_server_file(
|
|
|
57
57
|
parameters: Mapping[str, Any],
|
|
58
58
|
_exec_context: ExecContext | None = None,
|
|
59
59
|
) -> Mapping[str, Any]:
|
|
60
|
-
"""
|
|
60
|
+
"""Resolve a portable workspace file, preserving legacy absolute paths."""
|
|
61
61
|
path = parameters.get("file name", "")
|
|
62
62
|
if not isinstance(path, str):
|
|
63
63
|
raise TypeError("The selected file path parameter must be text")
|
|
64
64
|
if len(path) == 0:
|
|
65
65
|
raise ValueError("Path can't be empty")
|
|
66
|
-
|
|
66
|
+
source = Path(path).expanduser()
|
|
67
|
+
# Absolute paths from existing workflows remain external references.
|
|
68
|
+
if source.is_absolute():
|
|
69
|
+
return {"path": str(source)}
|
|
70
|
+
root = _exec_context.workspace if _exec_context is not None else None
|
|
71
|
+
if root is None:
|
|
72
|
+
raise ValueError("Workspace File requires a configured workspace directory")
|
|
73
|
+
source = (root / source).resolve()
|
|
74
|
+
if not source.is_relative_to(root):
|
|
75
|
+
raise ValueError("Workspace File path escapes the workspace directory")
|
|
76
|
+
if not source.is_file():
|
|
77
|
+
raise ValueError(f"Workspace file does not exist or is not a file: {path}")
|
|
78
|
+
return {"path": str(source)}
|
|
67
79
|
|
|
68
80
|
|
|
69
81
|
SELECT_SERVER_FILE = NodeDefinition(
|
|
70
82
|
cache_policy="pure",
|
|
71
|
-
id="
|
|
83
|
+
id="workspace-file",
|
|
72
84
|
requirements=(),
|
|
73
85
|
icon="mdi-cloud-upload-outline",
|
|
74
|
-
label="
|
|
75
|
-
description="
|
|
86
|
+
label="Workspace File",
|
|
87
|
+
description="Resolves a workspace-relative file path at runtime without reading the file. Legacy absolute paths remain external references.",
|
|
76
88
|
ports=(PortDefinition("path", PortDirection.OUTPUT, STRING, "File path"),),
|
|
77
89
|
executor=_select_server_file,
|
|
78
90
|
parameters=(
|
|
79
91
|
ParameterDefinition(
|
|
80
|
-
"file name", ParameterKind.SELECT_SERVER_FILENAME, "
|
|
92
|
+
"file name", ParameterKind.SELECT_SERVER_FILENAME, "Workspace file", "", port=False
|
|
81
93
|
),
|
|
82
94
|
),
|
|
83
95
|
)
|
|
@@ -87,6 +99,44 @@ class DirectoryReadError(ValueError):
|
|
|
87
99
|
"""Raised when a directory-file listing node receives an invalid directory path."""
|
|
88
100
|
|
|
89
101
|
|
|
102
|
+
def _workspace_directory(
|
|
103
|
+
_inputs: Mapping[str, Any],
|
|
104
|
+
parameters: Mapping[str, Any],
|
|
105
|
+
_exec_context: ExecContext | None = None,
|
|
106
|
+
) -> Mapping[str, Any]:
|
|
107
|
+
"""Resolve the selected relative folder within the host-configured workspace."""
|
|
108
|
+
root = _exec_context.workspace if _exec_context is not None else None
|
|
109
|
+
if root is None:
|
|
110
|
+
raise ValueError("Workspace Folder requires a configured workspace directory")
|
|
111
|
+
selected = parameters.get("folder", ".")
|
|
112
|
+
if not isinstance(selected, str):
|
|
113
|
+
raise TypeError("Workspace Folder selection must be text")
|
|
114
|
+
relative = Path(selected)
|
|
115
|
+
if relative.is_absolute() or PureWindowsPath(selected).anchor:
|
|
116
|
+
raise ValueError("Workspace Folder requires a workspace-relative folder path")
|
|
117
|
+
folder = (root / relative).resolve()
|
|
118
|
+
if not folder.is_relative_to(root):
|
|
119
|
+
raise ValueError("Workspace Folder path escapes the workspace directory")
|
|
120
|
+
if not folder.is_dir():
|
|
121
|
+
raise ValueError(f"Workspace folder does not exist or is not a directory: {selected}")
|
|
122
|
+
return {"path": folder}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
WORKSPACE = NodeDefinition(
|
|
126
|
+
cache_policy="pure",
|
|
127
|
+
id="workspace-folder",
|
|
128
|
+
requirements=(),
|
|
129
|
+
icon="mdi-folder-outline",
|
|
130
|
+
label="Workspace Folder",
|
|
131
|
+
description="Resolves a selected workspace-relative folder as an absolute directory path. Defaults to the workspace root.",
|
|
132
|
+
ports=(PortDefinition("path", PortDirection.OUTPUT, DIRECTORY, "Directory path"),),
|
|
133
|
+
executor=_workspace_directory,
|
|
134
|
+
parameters=(
|
|
135
|
+
ParameterDefinition("folder", ParameterKind.TEXT, "Workspace folder", ".", port=False),
|
|
136
|
+
),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
|
|
90
140
|
def _compile_filename_patterns(
|
|
91
141
|
pattern: object,
|
|
92
142
|
) -> re.Pattern[str] | None:
|
|
@@ -171,7 +221,7 @@ READ_DIRECTORY_FILES = NodeDefinition(
|
|
|
171
221
|
parameters=(
|
|
172
222
|
ParameterDefinition(
|
|
173
223
|
"path",
|
|
174
|
-
ParameterKind.
|
|
224
|
+
ParameterKind.DIRECTORY,
|
|
175
225
|
"Directory path",
|
|
176
226
|
"",
|
|
177
227
|
"/path/to/directory",
|
|
@@ -201,5 +251,6 @@ __all__ = [
|
|
|
201
251
|
"READ_DIRECTORY_FILES",
|
|
202
252
|
"SELECT_FILE",
|
|
203
253
|
"SELECT_SERVER_FILE",
|
|
254
|
+
"WORKSPACE",
|
|
204
255
|
"DirectoryReadError",
|
|
205
256
|
]
|
|
@@ -4,7 +4,6 @@ from collections.abc import Mapping, Sequence
|
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
6
|
import Muscat.MeshContainers.ElementsDescription as ED
|
|
7
|
-
import numpy as np
|
|
8
7
|
from Muscat.MeshContainers.Filters.FilterObjects import ElementFilter, NodeFilter
|
|
9
8
|
from Muscat.MeshContainers.Filters.FilterOperators import (
|
|
10
9
|
ComplementaryFilter,
|
|
@@ -189,16 +188,6 @@ CREATE_MUSCAT_ELEMENT_FILTER = NodeDefinition(
|
|
|
189
188
|
)
|
|
190
189
|
|
|
191
190
|
|
|
192
|
-
class _ComposedNodeFilter(NodeFilter):
|
|
193
|
-
"""Honor nested nodal filters omitted by Muscat's NodeFilter implementation."""
|
|
194
|
-
|
|
195
|
-
def GetNodesIndices(self, mesh):
|
|
196
|
-
indices = super().GetNodesIndices(mesh)
|
|
197
|
-
if self.nFilter is None:
|
|
198
|
-
return indices
|
|
199
|
-
return np.intersect1d(indices, self.nFilter.GetNodesIndices(mesh))
|
|
200
|
-
|
|
201
|
-
|
|
202
191
|
def _create_node_filter(
|
|
203
192
|
inputs: Mapping[str, Any],
|
|
204
193
|
parameters: Mapping[str, Any],
|
|
@@ -206,7 +195,7 @@ def _create_node_filter(
|
|
|
206
195
|
) -> Mapping[str, Any]:
|
|
207
196
|
"""Create a Muscat nodal selector from tags, zones, and nested selectors."""
|
|
208
197
|
return {
|
|
209
|
-
"filter":
|
|
198
|
+
"filter": NodeFilter(
|
|
210
199
|
nTag=_tag_list(parameters, "ntag") or None,
|
|
211
200
|
eTag=_tag_list(parameters, "etag") or None,
|
|
212
201
|
zone=[value for name, value in inputs.items() if name.startswith("zone_")],
|
|
@@ -45,7 +45,7 @@ class ImageOperationError(RuntimeError):
|
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
class ImageJConversionError(RuntimeError):
|
|
48
|
-
"""Raised when
|
|
48
|
+
"""Raised when conversion between Pillow and ImageJ image values fails."""
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
class ImageFluencyError(RuntimeError):
|
|
@@ -72,6 +72,34 @@ def _pillow_to_imagej(
|
|
|
72
72
|
return {"image": np.array(image, copy=True)}
|
|
73
73
|
|
|
74
74
|
|
|
75
|
+
def _imagej_to_pillow(
|
|
76
|
+
inputs: Mapping[str, Any],
|
|
77
|
+
_parameters: Mapping[str, Any],
|
|
78
|
+
_exec_context: ExecContext | None = None,
|
|
79
|
+
) -> Mapping[str, Any]:
|
|
80
|
+
"""Convert a single ImageJ NumPy image using Pillow's native array modes."""
|
|
81
|
+
array = inputs["image"]
|
|
82
|
+
if not isinstance(array, np.ndarray):
|
|
83
|
+
raise ImageJConversionError("ImageJ input must be a NumPy array")
|
|
84
|
+
if array.ndim not in (2, 3) or (array.ndim == 3 and array.shape[2] not in (2, 3, 4)):
|
|
85
|
+
raise ImageJConversionError(
|
|
86
|
+
"ImageJ input must have shape (height, width) or (height, width, channels) "
|
|
87
|
+
"with 2, 3, or 4 channels; select a single plane from stacks or volumes"
|
|
88
|
+
)
|
|
89
|
+
if array.shape[0] == 0 or array.shape[1] == 0:
|
|
90
|
+
raise ImageJConversionError("Image dimensions must both be at least one pixel")
|
|
91
|
+
try:
|
|
92
|
+
image = PillowImage.fromarray(array)
|
|
93
|
+
except (TypeError, ValueError) as error:
|
|
94
|
+
raise ImageJConversionError(
|
|
95
|
+
f"Cannot convert ImageJ array with shape {array.shape} and dtype {array.dtype} "
|
|
96
|
+
"to Pillow; use a Pillow-supported grayscale dtype or uint8 color channels"
|
|
97
|
+
) from error
|
|
98
|
+
# Reuse Pillow's buffer sharing where supported; Pillow writes detach the buffer.
|
|
99
|
+
image.readonly = 1
|
|
100
|
+
return {"image": image}
|
|
101
|
+
|
|
102
|
+
|
|
75
103
|
def _metric_channels(image: Image) -> tuple[np.ndarray, ...]:
|
|
76
104
|
"""Return image channels as float arrays, ignoring alpha channels."""
|
|
77
105
|
if image.mode == "L":
|
|
@@ -556,6 +584,20 @@ PILLOW_TO_IMAGEJ = NodeDefinition(
|
|
|
556
584
|
)
|
|
557
585
|
|
|
558
586
|
|
|
587
|
+
IMAGEJ_TO_PILLOW = NodeDefinition(
|
|
588
|
+
id="imagej-to-pillow",
|
|
589
|
+
requirements=("py:pillow", "py:numpy"),
|
|
590
|
+
icon="mdi-image-sync-outline",
|
|
591
|
+
label="ImageJ To Pillow",
|
|
592
|
+
description="Converts a single ImageJ NumPy image to a Pillow image without intensity scaling.",
|
|
593
|
+
ports=(
|
|
594
|
+
PortDefinition("image", PortDirection.INPUT, IMAGEJ, "ImageJ NumPy array"),
|
|
595
|
+
PortDefinition("image", PortDirection.OUTPUT, IMAGE, "Pillow image"),
|
|
596
|
+
),
|
|
597
|
+
executor=_imagej_to_pillow,
|
|
598
|
+
)
|
|
599
|
+
|
|
600
|
+
|
|
559
601
|
WRITE_IMAGE = NodeDefinition(
|
|
560
602
|
cache_policy="pure",
|
|
561
603
|
id="write-image",
|
|
@@ -731,6 +773,7 @@ IMAGE_FLUENCY_METRICS = NodeDefinition(
|
|
|
731
773
|
AVAILABLE_NODES = (
|
|
732
774
|
READ_IMAGE,
|
|
733
775
|
PILLOW_TO_IMAGEJ,
|
|
776
|
+
IMAGEJ_TO_PILLOW,
|
|
734
777
|
WRITE_IMAGE,
|
|
735
778
|
RESIZE_IMAGE,
|
|
736
779
|
CROP_IMAGE,
|
|
@@ -34,8 +34,8 @@ DEFAULT_CODE = """#@ Dataset image
|
|
|
34
34
|
result = image
|
|
35
35
|
"""
|
|
36
36
|
_DECLARATION = re.compile(
|
|
37
|
-
r"^\s*#@\s*(?:(input|output)\s+)?([\w.]+)
|
|
38
|
-
r"(?:\([^\n]*\)\s
|
|
37
|
+
r"^\s*#@\s*(?:(input|output)\s+)?([\w.]+)"
|
|
38
|
+
r"(?:\s*\([^\n]*\)\s*|\s+)([A-Za-z_$][\w$]*)\s*$",
|
|
39
39
|
re.IGNORECASE,
|
|
40
40
|
)
|
|
41
41
|
_UNTYPED_OUTPUT = re.compile(r"^\s*#@output\s+([A-Za-z_$][\w$]*)\s*$", re.IGNORECASE)
|
|
@@ -52,6 +52,7 @@ _TYPES = {
|
|
|
52
52
|
"Float": FLOAT,
|
|
53
53
|
"float": FLOAT,
|
|
54
54
|
"Dataset": IMAGEJ,
|
|
55
|
+
"ImagePlus": IMAGEJ,
|
|
55
56
|
"Img": IMAGEJ,
|
|
56
57
|
"RandomAccessibleInterval": IMAGEJ,
|
|
57
58
|
}
|
|
@@ -129,6 +130,64 @@ def _file_ports_for_instance(instance: NodeInstance) -> tuple[PortDefinition, ..
|
|
|
129
130
|
return (filename_port, *script_ports)
|
|
130
131
|
|
|
131
132
|
|
|
133
|
+
def _to_imageplus(array: np.ndarray) -> Any:
|
|
134
|
+
"""Build an owned ImageJ1 processor, preserving spatial and RGB semantics."""
|
|
135
|
+
import jpype
|
|
136
|
+
import scyjava
|
|
137
|
+
|
|
138
|
+
if not isinstance(array, np.ndarray) or array.ndim not in (2, 3):
|
|
139
|
+
raise ValueError("ImagePlus input requires a single grayscale or RGB NumPy image")
|
|
140
|
+
height, width = array.shape[:2]
|
|
141
|
+
if not height or not width:
|
|
142
|
+
raise ValueError("ImagePlus input dimensions must be positive")
|
|
143
|
+
if array.ndim == 3:
|
|
144
|
+
if array.shape[2] != 3 or array.dtype != np.uint8:
|
|
145
|
+
raise ValueError(
|
|
146
|
+
"ImagePlus color input requires uint8 RGB; convert alpha images to RGB explicitly"
|
|
147
|
+
)
|
|
148
|
+
packed = (
|
|
149
|
+
(array[:, :, 0].astype(np.int32) << 16)
|
|
150
|
+
| (array[:, :, 1].astype(np.int32) << 8)
|
|
151
|
+
| array[:, :, 2]
|
|
152
|
+
)
|
|
153
|
+
processor = scyjava.jimport("ij.process.ColorProcessor")(
|
|
154
|
+
width, height, jpype.JArray(jpype.JInt)(packed.ravel())
|
|
155
|
+
)
|
|
156
|
+
else:
|
|
157
|
+
types = {
|
|
158
|
+
np.dtype("uint8"): ("ByteProcessor", jpype.JByte, np.int8),
|
|
159
|
+
np.dtype("uint16"): ("ShortProcessor", jpype.JShort, np.int16),
|
|
160
|
+
np.dtype("float32"): ("FloatProcessor", jpype.JFloat, np.float32),
|
|
161
|
+
}
|
|
162
|
+
if array.dtype not in types:
|
|
163
|
+
raise ValueError("ImagePlus grayscale input requires uint8, uint16, or float32 pixels")
|
|
164
|
+
name, java_type, storage_type = types[array.dtype]
|
|
165
|
+
pixels = np.ascontiguousarray(array).view(storage_type).ravel()
|
|
166
|
+
processor = scyjava.jimport(f"ij.process.{name}")(
|
|
167
|
+
width, height, jpype.JArray(java_type)(pixels), None
|
|
168
|
+
)
|
|
169
|
+
return scyjava.jimport("ij.ImagePlus")("FlowGraph image", processor)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _from_imageplus(image: Any) -> np.ndarray:
|
|
173
|
+
"""Read current processor pixels, not a potentially stale Dataset conversion."""
|
|
174
|
+
if image.getStackSize() != 1:
|
|
175
|
+
raise ValueError(
|
|
176
|
+
"ImagePlus output is a stack; select a single image plane before returning"
|
|
177
|
+
)
|
|
178
|
+
shape = (image.getHeight(), image.getWidth())
|
|
179
|
+
pixels = np.asarray(image.getProcessor().getPixels()).reshape(shape)
|
|
180
|
+
if image.getType() == 4: # ImagePlus.COLOR_RGB: packed 0xRRGGBB integers.
|
|
181
|
+
rgb = np.empty((*shape, 3), dtype=np.uint8)
|
|
182
|
+
for channel, shift in enumerate((16, 8, 0)):
|
|
183
|
+
rgb[:, :, channel] = (pixels >> shift) & 255
|
|
184
|
+
return rgb
|
|
185
|
+
dtypes = {0: np.uint8, 1: np.uint16, 2: np.float32}
|
|
186
|
+
if image.getType() not in dtypes:
|
|
187
|
+
raise ValueError("ImagePlus output must be grayscale or RGB, not indexed color")
|
|
188
|
+
return pixels.view(dtypes[image.getType()]).copy()
|
|
189
|
+
|
|
190
|
+
|
|
132
191
|
def _execute_script(
|
|
133
192
|
inputs: Mapping[str, Any],
|
|
134
193
|
source: str,
|
|
@@ -153,7 +212,9 @@ def _execute_script(
|
|
|
153
212
|
if port.direction is not PortDirection.INPUT or port.name not in inputs:
|
|
154
213
|
continue
|
|
155
214
|
value = inputs[port.name]
|
|
156
|
-
if declared_type == "
|
|
215
|
+
if declared_type == "ImagePlus":
|
|
216
|
+
value = _to_imageplus(value)
|
|
217
|
+
elif declared_type == "Dataset":
|
|
157
218
|
value = ij.py.to_dataset(value)
|
|
158
219
|
elif declared_type in {"Img", "RandomAccessibleInterval"}:
|
|
159
220
|
value = ij.py.to_img(value)
|
|
@@ -161,15 +222,35 @@ def _execute_script(
|
|
|
161
222
|
value = ij.py.to_java(value)
|
|
162
223
|
args[port.name] = value
|
|
163
224
|
|
|
225
|
+
# ImagePlus is not always present in SciJava's short-name type aliases.
|
|
226
|
+
source = re.sub(
|
|
227
|
+
r"(^\s*#@\s*(?:(?:input|output)\s+)?)ImagePlus(?=\s|\()",
|
|
228
|
+
r"\1ij.ImagePlus",
|
|
229
|
+
source,
|
|
230
|
+
flags=re.MULTILINE,
|
|
231
|
+
)
|
|
164
232
|
result = ij.py.run_script("Groovy", source, args)
|
|
165
233
|
outputs: dict[str, Any] = {}
|
|
166
|
-
for port,
|
|
234
|
+
for port, declared_type in declarations:
|
|
167
235
|
if port.direction is not PortDirection.OUTPUT:
|
|
168
236
|
continue
|
|
169
237
|
if port.name not in result:
|
|
170
238
|
raise ValueError(f"ImageJ script did not produce output {port.name!r}")
|
|
171
|
-
|
|
172
|
-
|
|
239
|
+
raw_value = result[port.name]
|
|
240
|
+
value = (
|
|
241
|
+
_from_imageplus(raw_value)
|
|
242
|
+
if declared_type == "ImagePlus" and raw_value is not None
|
|
243
|
+
else ij.py.from_java(raw_value)
|
|
244
|
+
)
|
|
245
|
+
if port.data_type == IMAGEJ and value is None:
|
|
246
|
+
raise ValueError(
|
|
247
|
+
f"ImageJ script output {port.name!r} is null; check the Fiji/Groovy error log "
|
|
248
|
+
"and assign a valid image to the declared output. "
|
|
249
|
+
"IJ.run(image, command, options) requires an ImagePlus, not a Dataset."
|
|
250
|
+
)
|
|
251
|
+
if port.data_type == IMAGEJ and declared_type != "ImagePlus":
|
|
252
|
+
value = np.asarray(value).copy()
|
|
253
|
+
outputs[port.name] = value
|
|
173
254
|
return outputs
|
|
174
255
|
|
|
175
256
|
|