Skip to content

Create single-file plugins with datalab-plugin create - #414

Merged
PierreRaybaut merged 4 commits into
developfrom
feature/413-single-file-plugins
Oct 21, 2026
Merged

PierreRaybaut merged 4 commits into
developfrom
feature/413-single-file-plugins

Conversation

@PierreRaybaut

@PierreRaybaut PierreRaybaut commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #413.

Problem

datalab-plugin create only created a layered installable project of about 17 files (pyproject.toml, src layout, core/workflow/adapters, tests, release workflow). This suits plugins published in the plugin catalog, but it is far too much for DataLab users who are not software developers and simply want to add a processing, although DataLab loads a plugin that is a single datalab_<name>.py file.

Feature

datalab-plugin create now creates a single-file plugin by default:

  • only the plugin name and description are asked; the module name (datalab_<name>), plugin ID and destination are derived, and remain overridable with --package, --plugin-id and the destination argument;
  • the file is written to the user plugin directory, the one DataLab scans, so that Plugins > Reload plugins loads it; for another folder, the command tells to add it to the plugin directories;
  • the file registers a sample processing listed in the plugin submenu of the Plugins menu; users only edit a short NumPy function (sample_processing(y) for signals, sample_processing(data) for images with --object-kind image), registered as it is, wrapped with Wrap1to1Func (accepted since Register NumPy functions wrapped with Wrap1to1Func in plugins #416); without the processing capability, the submenu holds an action showing a message;
  • user values are written as readable Python strings, accents included, quoted as Ruff formats them; the file passes ruff format and ruff check (E, F, I);
  • the datalab_ prefix is enforced, and an existing file is never overwritten;
  • the file can be shared and installed with Plugins > Configure plugins... > Install plugins.

The layered installable project is created with --project, with an unchanged output.

Python API (foundation for #377)

datalab/plugins/generator.py exposes render_single_file_plugin, create_single_file_plugin and get_default_plugin_folder, usable without the command line, as #377 requires for its Plugins > New plugin... wizard. The rendering is split into fragments (imports, sample processing, menu action, plugin declaration) that the wizard may extend. The wizard, its composable templates, author and version fields, configuration updates, immediate loading and external editor remain in the scope of #377.

Behaviour changes

  • datalab-plugin create without --project creates a single file instead of a project. The command has not been released yet (DataLab 1.4).
  • Accents are removed from the names derived from the plugin name, for projects too: "Filtres améliorés" gives datalab_filtres_ameliores and FiltresAmelioresPlugin, instead of datalab_filtres_am_lior_s and FiltresAmLiorSPlugin. ASCII names give the same results as before.

Tests

  • plugin_generator_unit_test.py: the existing project tests now pass --project and are otherwise unchanged. New tests: single file by default without any question; only two questions in interactive mode, with accents; signal, image and application-only files passing Ruff and discovered from a plugin directory; default folder equal to PLUGINS_DEFAULT_PATH; no overwrite, from the API and the CLI; module names without datalab_ refused; quotes and accents kept; generated file accepted by the plugin store (Install plugins).
  • New plugin_single_file_app_test.py: in DataLab, the generated plugin adds its menu entry, its processing computes the expected values, also after Reload plugins.
  • Project output compared with the generator of develop for seven configurations (capabilities, object kinds, quotes, accents, long metadata): identical.
  • Generated signal and image processings registered as DataLab does and executed on SignalObj and ImageObj (values and data type).
  • Real CLI run: help, creation, refused overwrite, French messages.
  • Regression, after rebasing on develop (including Register NumPy functions wrapped with Wrap1to1Func in plugins #416): datalab/tests/backbone/plugins, datalab/tests/features/plugins, processor registry and feature identity tests, 253 passed.
  • Ruff format and check; Pylint 10/10 on the changed modules; French documentation built with -W.

Documentation and translations

  • doc/features/advanced/plugins.rst: new section "Creating a plugin with datalab-plugin create"; the layered project section uses --project.
  • Release notes 1.4 (Plugin project generator).
  • French translations of the new UI messages and of the changed documentation entries only.

Out of scope

@PierreRaybaut

Copy link
Copy Markdown
Contributor Author

Follow-up planned once #416 is merged: #416 (fixes #415) lets 1-to-1 features register a NumPy function wrapped with Wrap1to1Func directly, which register_1_to_1 refused so far. This branch will then be rebased on develop, and the generated single-file plugin simplified to register sips.Wrap1to1Func(sample_processing) (or sipi.Wrap1to1Func(...) for images) directly, without the compute_sample_processing function decorated with @computation_function() and its imports.

…413)

`datalab-plugin create` now creates a single-file plugin by default: it
only asks for the plugin name and description, then writes a
`datalab_<name>.py` file to the user plugin directory, which DataLab
loads once the plugins are reloaded. The file registers a sample
processing, listed in the plugin submenu of the Plugins menu, whose
short NumPy function is the only part to edit (signals, or images with
`--object-kind image`); without the processing capability, the submenu
holds an action showing a message. The layered installable project is
unchanged and created with `--project`.

- Python API, usable without the command line (#377):
  `render_single_file_plugin`, `create_single_file_plugin` and
  `get_default_plugin_folder`. The `datalab_` prefix is enforced and an
  existing file is never overwritten.
- User values are written as readable Python strings, accents included,
  quoted as Ruff formats them.
- Accents are removed from the names derived from the plugin name, e.g.
  `datalab_filtres_ameliores` and `FiltresAmelioresPlugin` for
  "Filtres améliorés", for projects too.
- French translations of the new messages.

Assisted-by: Claude Opus 5.5
Generated files pass Ruff, keep the typed name and description, and are
discovered from any plugin directory for signals, images and
application-only plugins. Only two questions are asked, the default
folder is DataLab's user plugin directory, existing files are never
overwritten, module names without the `datalab_` prefix are refused, and
files are accepted by the Install plugins tab. In DataLab, the generated
plugin adds its menu entry and processing, also after reloading the
plugins.

The existing project tests now pass `--project` and are otherwise
unchanged.

Assisted-by: Claude Opus 5.5
The plugin documentation presents `datalab-plugin create` as the way to
create a single-file plugin, and the layered project with `--project`.
Release notes 1.4 (Plugin project generator) with their French
translation.

Assisted-by: Claude Opus 5.5
Since #416 (#415), 1-to-1 features accept a NumPy function wrapped with
Sigima's `Wrap1to1Func`. Generated single-file plugins now register
`Wrap1to1Func(sample_processing)` directly, without the decorated
`compute_sample_processing` function and the imports it needed: the
generated file is shorter, and its only function is the one to edit.

Assisted-by: Claude Opus 5.5
@PierreRaybaut
PierreRaybaut force-pushed the feature/413-single-file-plugins branch from 6e5576c to 4a8d849 Compare October 21, 2026 15:08
@PierreRaybaut
PierreRaybaut merged commit 8398ad9 into develop Oct 21, 2026
6 checks passed
@PierreRaybaut
PierreRaybaut deleted the feature/413-single-file-plugins branch October 23, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant