spyder.api.plugin_registration.registry#

Global plugin registry.

Classes

PreferencesAdapter()

SpyderPluginRegistry()

Global plugin registry.

class spyder.api.plugin_registration.registry.PreferencesAdapter[source]#

Bases: SpyderConfigurationAccessor

CONF_WIDGET_CLASS#

alias of PluginsConfigPage

class spyder.api.plugin_registration.registry.SpyderPluginRegistry[source]#

Bases: QObject, PreferencesAdapter

Global plugin registry.

This class handles a plugin initialization/teardown lifetime, including notifications when a plugin is available or not.

This registry alleviates the limitations of a topological sort-based plugin initialization by enabling plugins to have bidirectional dependencies instead of unidirectional ones.

Notes

  1. This class should be instantiated as a singleton.

  2. A plugin should not depend on other plugin to perform its initialization since it could cause deadlocks.

sig_plugin_ready#

This signal is used to let the main window know that a plugin is ready.

Parameters:
  • plugin_name (str) – Name of the plugin that is available.

  • omit_conf (bool) – True if the plugin configuration does not need to be written.

register_plugin(main_window: Any, PluginClass: Type[SpyderPluginV2 | SpyderDockablePlugin], *args: tuple, external: bool = False, **kwargs: dict) SpyderPluginV2 | SpyderDockablePlugin[source]#

Register a plugin into the Spyder registry.

Parameters:
  • main_window (spyder.app.mainwindow.MainWindow) – Reference to Spyder’s main window.

  • PluginClass (type[SpyderPluginClass]) – The plugin class to register and create. It must be one of spyder.app.registry.SpyderPluginClass.

  • *args (tuple) – Positional arguments used to initialize the plugin instance.

  • external (bool) – If True, then the plugin is stored as a external plugin. Otherwise it will be marked as an internal plugin. Default: False

  • **kwargs (dict) – Optional keyword arguments used to initialize the plugin instance.

Returns:

plugin – The instance of the registered plugin.

Return type:

SpyderPluginClass

Raises:

TypeError – If the PluginClass does not inherit from any of spyder.app.registry.SpyderPluginClass

Notes

The optional *args and **kwargs will be removed once all plugins are migrated.

notify_plugin_availability(plugin_name: str, notify_main: bool = True, omit_conf: bool = False)[source]#

Notify dependent plugins of a given plugin of its availability.

Parameters:
  • plugin_name (str) – Name of the plugin that is available.

  • notify_main (bool) – If True, then a signal is emitted to the main window to perform further registration steps.

  • omit_conf (bool) – If True, then the main window is instructed to not write the plugin configuration into the Spyder configuration file.

can_delete_plugin(plugin_name: str) bool[source]#

Check if a plugin from the registry can be deleted by its name.

Paremeters#

plugin_name: str

Name of the plugin to check for deletion.

returns:

can_close – True if the plugin can be closed. False otherwise.

rtype:

bool

dock_undocked_plugin(plugin_name: str, save_undocked: bool = False)[source]#

Dock plugin if undocked and save undocked state if requested

Parameters:
  • plugin_name (str) – Name of the plugin to check for deletion.

  • save_undocked (bool, optional) – True if the undocked state needs to be saved. The default is False.

Return type:

None.

delete_plugin(plugin_name: str, teardown: bool = True, check_can_delete: bool = True) bool[source]#

Remove and delete a plugin from the registry by its name.

Paremeters#

plugin_name: str

Name of the plugin to delete.

teardown: bool

True if the teardown notification to other plugins should be sent when deleting the plugin, False otherwise.

check_can_delete: bool

True if the plugin should validate if it can be closed when this method is called, False otherwise.

returns:

plugin_deleted – True if the registry was able to teardown and remove the plugin. False otherwise.

rtype:

bool

dock_all_undocked_plugins(save_undocked: bool = False)[source]#

Dock undocked plugins and save undocked state if required.

Parameters:

save_undocked (bool, optional) – True if the undocked state needs to be saved. The default is False.

Return type:

None.

can_delete_all_plugins(excluding: Set[str] | None = None) bool[source]#

Determine if all plugins can be deleted except the ones to exclude.

Parameters:

excluding (Optional[Set[str]]) – A set that lists plugins (by name) that will not be deleted.

Returns:

True if all plugins can be closed. False otherwise.

Return type:

bool

delete_all_plugins(excluding: Set[str] | None = None, close_immediately: bool = False) bool[source]#

Remove all plugins from the registry.

The teardown mechanism will remove external plugins first and then internal ones, where the Spyder 4 plugins will be removed first and then the Spyder 5 ones.

Parameters:
  • excluding (Optional[Set[str]]) – A set that lists plugins (by name) that will not be deleted.

  • close_immediately (bool) – If true, then the can_close status will be ignored.

Returns:

all_deleted – True if all the plugins were closed and deleted. False otherwise.

Return type:

bool

get_plugin(plugin_name: str) SpyderPluginV2 | SpyderDockablePlugin[source]#

Get a reference to a plugin instance by its name.

Parameters:

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

Returns:

plugin – The instance of the requested plugin.

Return type:

SpyderPluginClass

Raises:

SpyderAPIError – If the plugin name was not found in the registry.

set_plugin_enabled(plugin_name: str)[source]#

Add a plugin name to the set of enabled plugins.

Parameters:

plugin_name (str) – Name of the plugin to add.

is_plugin_enabled(plugin_name: str) bool[source]#

Determine if a given plugin is enabled and is going to be loaded.

Parameters:

plugin_name (str) – Name of the plugin to query.

Returns:

plugin_enabled – True if the plugin is enabled and False if not.

Return type:

bool

is_plugin_available(plugin_name: str) bool[source]#

Determine if a given plugin was loaded and is available.

Parameters:

plugin_name (str) – Name of the plugin to query.

Returns:

plugin_available – True if the plugin is available and False if not.

Return type:

bool

reset()[source]#

Reset and empty the plugin registry.