Repository navigation
Plugins cannot register NumPy functions wrapped with Wrap1to1Func (documented example fails) #415
Description
Summary
The documented processing plugin example plugins/examples/datalab_custom_func.py, used by the Custom function tutorial and the plugin guide, no longer loads on develop. Its registration fails with:
ValueError: 'weighted_average_denoise' is not a valid computation function.
The plugin therefore adds no menu entry. Any plugin following the documented pattern — registering a NumPy function wrapped with sigima.proc.image.Wrap1to1Func (or sigima.proc.signal.Wrap1to1Func) through register_1_to_1 — fails in the same way.
This regression only exists on develop: no released version is affected (latest: v1.3.0).
When it happens
- Copy
plugins/examples/datalab_custom_func.pyto a plugin directory. - Start DataLab or reload the plugins.
- Its
register_computations()raises the error above, and the "My custom filters" menu does not appear.
import sigima.proc.image as sipi
from datalab.gui.processor.base import ComputingFeature
ComputingFeature(
"1_to_1",
function=sipi.Wrap1to1Func(weighted_average_denoise),
feature_id="org.datalab.examples.custom-filters:weighted-average-denoise",
owner_plugin_id="org.datalab.examples.custom-filters",
) # ValueError: 'weighted_average_denoise' is not a valid computation function.Root cause
ComputingFeature.__post_init__ only accepts functions decorated with Sigima's @computation_function(). Commit ccb81ef ("feat: add plugin-owned processing lifecycle") moved the example from compute_1_to_1(wrapped_func), which does not check the function, to register_1_to_1(wrapped_func, ...), which does. No test loads the shipped examples in DataLab: test_plugin_examples_import only imports them.
Yet a Wrap1to1Func instance is a valid feature function: it is picklable (as required by the process pool), named after the wrapped function, and returns the expected object. Sigima documents it as usable "as a Sigima computation function and inside DataLab's infrastructure", and DataLab already detects the plugin origin of such wrappers (_detect_plugin_origin).
Proposed fix
- Registered 1-to-1 features accept the
Wrap1to1Funcinstances ofsigima.proc.signalandsigima.proc.image, besides decorated computation functions. The example, the tutorial and the migration guide stay unchanged: wrapping a NumPy function remains the simplest way to add a processing. - Other callables remain refused, with an error message naming both accepted forms, so that mistakes are reported at registration rather than when processing in a separate process. A wrapper registered for another pattern than 1-to-1 is refused as well.
- A new application test loads every shipped example plugin in DataLab and runs the processing of the custom function example, also after reloading the plugins.
- The plugin guide states which functions processing plugins may register.
Out of scope
- Release notes: the regression was never released.
- Simplifying the single-file plugin generated by
datalab-plugin create(Create single-file plugins with datalab-plugin create #413, Create single-file plugins with datalab-plugin create #414), which will register the wrapper directly once this is fixed.
Activity
fix(plugins): register NumPy functions wrapped with Wrap1to1Func (#415)
test(plugins): load every shipped example plugin in DataLab (#415)
docs(plugins): state which functions processing plugins may register (#…
refactor(plugins): register the generated NumPy function as it is (#413)