Repository navigation
feat(backends): a registry of backends by name - #953
Merged
Merged
Conversation
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>
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Security | 1 critical |
🟢 Metrics 57 complexity · 0 duplication
Metric Results Complexity 57 Duplication 0
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.
This was referenced Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.targetis a lazy"module:Class"string, imported only when the backend is chosen, or a callable that returns one.load_backend()was anif/elifover three names and now uses the registry. An unknown name lists the registered ones, and a missing package names the pip extra.robot.default_backend = "Swift"used to be kept as given and failed withValueErrorat 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. Thebackendargument ofplot()andteach()was aLiteral["swift", "pyplot", "pyplot2"], which would reject a registered backend; it is nowstr, checked at run time against the registry.plot()asks a backend what it can do instead of what class it is. It recognised Swift bytype(env).__name__ == "Swift"and PyPlot byisinstance, 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 onConnector, bothFalseby default, replace those checks:embeds_in_notebook(set by Swift) andsupports_movie(set by PyPlot). They are read withgetattr, likesupports_teachandsupports_ellipse.docs/source/arm_backend.rstdocuments 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_backendline.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 aTypeErrorwhere it is set.register_backendand the two flags are new public API.What I ran, and what I could not
main(4 commits, no conflicts). The whole suite (apart fromtests/test_blocks.py) on the pure-Python path in a clean venv: 2413 passed, 0 failed.tests/test_blocks.pyandtests/test_block_parameters.py: 53 passed.tests/test_backend_registry.py,tests/test_backend_flags.pyandtests/test_default_backend.py.-j): 35 warnings, identical to a build ofmain; the new page rendered.AI assistance
Written with Claude Code (Claude Sonnet 5.5), reviewed by the maintainer.
🤖 Generated with Claude Code