Skip to content

feat(backends): a registry of backends by name - #953

Merged
petercorke merged 4 commits into
mainfrom
feat/backend-registry
Nov 18, 2026
Merged

petercorke merged 4 commits into
mainfrom
feat/backend-registry

Conversation

@petercorke

Copy link
Copy Markdown
Owner

What

A registry of plotting backends by name, so a backend can be added without editing the Toolbox. Part of Issue #902, and the groundwork for Issue #886.

  • register_backend(name, target) adds a backend. target is a lazy "module:Class" string, imported only when the backend is chosen, or a callable that returns one. load_backend() was an if/elif over three names and now uses the registry. An unknown name lists the registered ones, and a missing package names the pip extra.
  • Backend names are not case sensitive and are plain strings. robot.default_backend = "Swift" used to be kept as given and failed with ValueError at plot time. The name is now normalised where it is set (default_backend, set_default_backend) and where it is given (plot, teach), by one function. The backend argument of plot() and teach() was a Literal["swift", "pyplot", "pyplot2"], which would reject a registered backend; it is now str, checked at run time against the registry.
  • plot() asks a backend what it can do instead of what class it is. It recognised Swift by type(env).__name__ == "Swift" and PyPlot by isinstance, so a new backend could not be a web page in a notebook, or make a movie, without being named like one of them. Two flags on Connector, both False by default, replace those checks: embeds_in_notebook (set by Swift) and supports_movie (set by PyPlot). They are read with getattr, like supports_teach and supports_ellipse.
  • The new section in docs/source/arm_backend.rst documents the registry and the flags.

This builds on the Connector abstract class from PR #923 (merged). It supersedes the lower-casing in PR #904, and Alex's Isaac Sim work in PR #907 (Isaac Sim backend, work in progress) becomes one register_backend line.

Behaviour

No change to what the built-in backends do. Two things change for callers: backend names such as "Swift" are now accepted in any case, and a name that is not a string is a TypeError where it is set. register_backend and the two flags are new public API.

What I ran, and what I could not

  • Rebased on main (4 commits, no conflicts). The whole suite (apart from tests/test_blocks.py) on the pure-Python path in a clean venv: 2413 passed, 0 failed. tests/test_blocks.py and tests/test_block_parameters.py: 53 passed.
  • New tests: tests/test_backend_registry.py, tests/test_backend_flags.py and tests/test_default_backend.py.
  • Docs built the way CI builds them (no -j): 35 warnings, identical to a build of main; the new page rendered.
  • Not run: the compiled path, a live Swift in a browser, and Isaac Sim.

AI assistance

Written with Claude Code (Claude Sonnet 5.5), reviewed by the maintainer.

🤖 Generated with Claude Code

petercorke and others added 4 commits November 18, 2026 07:19
load_backend() was an if/elif over three names.  The names are now entries in
a registry, and register_backend() adds more: a lazy "module:Class" string, which
is imported only when the backend is chosen, or a callable that returns one.
Names are not case sensitive.  An unknown name lists the registered ones, and a
missing package names the pip extra.  This is groundwork for #886, so a backend
can be developed and used outside the Toolbox.

Part of #902.  No change to what the built-in backends do.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…strings

robot.default_backend = "Swift" was kept as given and failed with ValueError at
plot time.  The name is now normalised where it is set (default_backend and
set_default_backend) and where it is given (plot and teach), by one function in
the registry.  A name that is not a string is a TypeError where it is set.

The backend argument of plot() and teach() was Literal["swift", "pyplot",
"pyplot2"], which would reject a registered backend; it is now str, checked at
runtime against the registry.

Part of #902.  Supersedes the lower-casing in #904.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… it is

plot() recognised Swift by type(env).__name__ == "Swift" and PyPlot by
isinstance, so a new backend could not be a web page shown in a notebook, or
make a movie, without being named or derived like one of them.  Two flags on
Connector, both False by default, replace the checks:

- embeds_in_notebook: the backend is a web page that can be shown in the cell
  of a notebook (set by Swift), which plot() asks for in a notebook, and
  paces an animation in real time
- supports_movie: the backend has getframe() (set by PyPlot)

They are read with getattr, as supports_teach and supports_ellipse are, so a
backend that does not inherit from Connector, as Swift does not, need not
define them.  Behaviour of the built-in backends is unchanged.

Part of #902.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 critical

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
Security 1 critical

View in Codacy

🟢 Metrics 57 complexity · 0 duplication

Metric Results
Complexity 57
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit 089de1c into main Nov 18, 2026
26 of 27 checks passed
@petercorke
petercorke deleted the feat/backend-registry branch November 18, 2026 05:05
@github-actions github-actions Bot mentioned this pull request Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant