Skip to content

Plugins cannot register NumPy functions wrapped with Wrap1to1Func (documented example fails) #415

Closed

Description

@PierreRaybaut

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

  1. Copy plugins/examples/datalab_custom_func.py to a plugin directory.
  2. Start DataLab or reload the plugins.
  3. 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 Wrap1to1Func instances of sigima.proc.signal and sigima.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions