nlsq.diagnostics.PluginRegistry

class nlsq.diagnostics.PluginRegistry[source]

Bases: object

Global registry for diagnostic plugins.

Thread-safe singleton for managing plugin registration. Plugins are stored by name and can be registered, unregistered, retrieved, or listed.

This class uses class-level storage and methods, so it acts as a singleton without explicit instantiation.

Example

>>> from nlsq.diagnostics import PluginRegistry
>>> # Register a plugin
>>> PluginRegistry.register(my_plugin)
>>> # Get a plugin by name
>>> plugin = PluginRegistry.get("my-plugin")
>>> # List all plugins
>>> all_plugins = PluginRegistry.all()
>>> # Clear all plugins (for testing)
>>> PluginRegistry.clear()
classmethod register(plugin)[source]

Register a diagnostic plugin.

Parameters:

plugin (DiagnosticPlugin) – Plugin instance to register.

Raises:

ValueError – If a plugin with the same name is already registered.

Example

>>> PluginRegistry.register(MyPlugin())
classmethod unregister(name)[source]

Unregister a plugin by name.

Parameters:

name (str) – Name of the plugin to unregister.

Returns:

True if the plugin was found and removed, False otherwise.

Return type:

bool

Example

>>> PluginRegistry.unregister("my-plugin")
True
classmethod get(name)[source]

Get a plugin by name.

Parameters:

name (str) – Name of the plugin to retrieve.

Returns:

Plugin instance if found, None otherwise.

Return type:

DiagnosticPlugin | None

Example

>>> plugin = PluginRegistry.get("my-plugin")
>>> if plugin is not None:
...     result = plugin.analyze(...)
classmethod all()[source]

Get all registered plugins.

Returns:

List of all registered plugin instances. This is a copy; modifying it does not affect the registry.

Return type:

list[DiagnosticPlugin]

Example

>>> for plugin in PluginRegistry.all():
...     print(plugin.name)
classmethod clear()[source]

Unregister all plugins.

Primarily for testing purposes.

Example

>>> PluginRegistry.clear()
>>> assert len(PluginRegistry.all()) == 0