spyder.api.plugin_registration.registry#

Global registry for internal and external Spyder plugins.

Module Attributes

SpyderPluginClass

Type alias for the set of supported classes for Spyder plugin objects.

ALL_PLUGINS

List of all Spyder internal plugins.

PLUGIN_REGISTRY

The global Spyder plugin registry instance.

Classes

PreferencesAdapter()

Class with constants for the plugin manager preferences page.

SpyderPluginRegistry()

Global Spyder plugin registry.

spyder.api.plugin_registration.registry.SpyderPluginClass#

Type alias for the set of supported classes for Spyder plugin objects.

alias of SpyderPluginV2 | SpyderDockablePlugin

spyder.api.plugin_registration.registry.ALL_PLUGINS: list[str] = ['appearance', 'application', 'completions', 'internal_console', 'debugger', 'editor', 'explorer', 'external_terminal', 'find_in_files', 'help', 'historylog', 'ipython_console', 'layout', 'main_interpreter', 'mainmenu', 'onlinehelp', 'outline_explorer', 'plots', 'preferences', 'profiler', 'project_explorer', 'pylint', 'pythonpath_manager', 'remoteclient', 'run', 'shortcuts', 'statusbar', 'switcher', 'toolbar', 'tours', 'update_manager', 'variable_explorer', 'workingdir']#

List of all Spyder internal plugins.

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

Bases: SpyderConfigurationAccessor

Class with constants for the plugin manager preferences page.

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

Bases: QObject, PreferencesAdapter

Global Spyder plugin registry.

This class handles a plugin’s initialization/teardown lifetime, including notifications when a plugin is available or about to be torn down.

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

Caution

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

Note

This class should be instantiated as a singleton.

sig_plugin_ready(QString, bool): Signal#

Signal used to let the main window know that a plugin is ready for use.

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

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

__init__() None[source]#

Create a global registry for internal and external Spyder plugins.

Return type:

None

main: spyder.app.mainwindow.MainWindow | None#

Reference to the Spyder main window.

plugin_dependents: dict[str, dict[str, list[str]]]#

Mapping of plugin names to the names of plugins depending on them.

The second-level dictionary holds lists of dependencies for the plugin by category, under the keys "requires" and "optional".

plugin_dependencies: dict[str, dict[str, list[str]]]#

Mapping of plugin names to the names of plugins they depend on.

The second-level dictionary holds lists of dependencies for the plugin by category, under the keys "requires" and "optional".

plugin_registry: dict[str, SpyderPluginClass]#

Mapping of plugin names to plugin objects.

plugin_availability: dict[str, bool]#

Mapping of plugin name to whether it is ready for use.

enabled_plugins: set[str]#

Set of the names of all enabled plugins.

internal_plugins: set[str]#

Set of the names of all internal plugins (part of Spyder itself).

external_plugins: set[str]#

Set of the names of all external plugins (installed separately).

all_internal_plugins: dict[str, tuple[str, type[SpyderPluginClass]]]#

Mapping of internal plugins to their name and plugin class.

Includes all internal plugins that are part of Spyder’s source tree, enabled or not.

all_external_plugins: dict[str, tuple[str, type[SpyderPluginClass]]]#

Mapping of external plugins to their name and plugin class.

Includes all externals plugins installed separately from Spyder, enabled or not.

register_plugin(main_window: spyder.app.mainwindow.MainWindow, PluginClass: type[SpyderPluginClass], *args: Any, external: bool = False, **kwargs: Any) SpyderPluginClass[source]#

Register a plugin into the Spyder plugin 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 SpyderPluginClass.

  • *args (Any, optional) –

    Arbitrary positional arguments passed to the plugin instance’s initializer.

    Deprecated since version 6.2: No longer needed following completion of the Spyder plugin API migration in Spyder 6.0. Passing *args will raise a DeprecationWarning in Spyder 6.2 and be removed in Spyder 7.0.

  • external (bool, optional) – If True, then the plugin is stored as an external plugin. Otherwise, it will be marked as an internal plugin (the default).

  • **kwargs (Any, optional) –

    Arbitrary positional arguments passed to the plugin instance’s initializer.

    Deprecated since version 6.2: No longer needed following completion of the Spyder plugin API migration in Spyder 6.0. Passing **kwargs will raise a DeprecationWarning in Spyder 6.2 and be removed in Spyder 7.0.

Returns:

plugin – The initialized instance of the registered plugin.

Return type:

SpyderPluginClass

Raises:

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

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

Notify a plugin’s dependents that the plugin is ready for use.

Parameters:
  • plugin_name (str) – Name of the plugin that has become ready for use.

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

  • omit_conf (bool, optional) – If True, then the main window is instructed to not write the plugin configuration into the Spyder configuration file. Otherwise, configuration will be written as normal (the default).

Return type:

None

can_delete_plugin(plugin_name: str) bool[source]#

Check if a plugin with the given name can be deleted from the registry.

Calls spyder.api.plugins.SpyderPluginV2.can_close() to perform the check.

Parameters:

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

Returns:

can_closeTrue if the plugin can be removed; False otherwise.

Return type:

bool

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

Dock plugin if undocked and save undocked state if requested.

Parameters:
  • plugin_name (str) – Name of the plugin to undock.

  • save_undocked (bool, optional) – True if the undocked state should be saved. If False, the default, don’t persist the undocked state.

Return type:

None

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

Remove and delete the plugin with the given name from the registry.

Parameters:
  • plugin_name (str) – Name of the plugin to delete.

  • teardown (bool, optional) – True if the teardown notification to other plugins should be sent when deleting the plugin (the default), False otherwise.

  • check_can_delete (bool, optional) – True if the plugin should first check if it can be deleted (using can_delete_plugin()) before closing and removing itself from the registry (the default). If this check then fails, the plugin’s removal is aborted and this method returns False. Otherwise, if this parameter is False, the plugin is deleted unconditionally without a check.

Returns:

plugin_deletedTrue if the registry was able to teardown and remove the plugin; False otherwise. Will always return True if check_can_delete is False.

Return type:

bool

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

Dock undocked plugins and save the undocked state if requested.

Parameters:

save_undocked (bool, optional) – True if the undocked state should be saved. If False, the default, don’t persist the undocked state.

Return type:

None

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

Determine if all plugins can be deleted (except any specified).

Calls spyder.api.plugins.SpyderPluginV2.can_close() to perform the check.

Parameters:

excluding (set[str] | None, optional) – A set that lists plugins (by name) that will not be checked for deletion. If None (the default) or an empty set, no plugins are excluded from the check.

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 then internal ones.

Parameters:
  • excluding (set[str] | None, optional) – A set that lists plugins (by name) that will not be deleted. If None (the default) or an empty set, no plugins are excluded from being deleted.

  • close_immediately (bool, optional) – If True, then the can_close() status will be ignored, and all plugins will be closed unconditionally. If False (the default), Spyder will not close any plugins if they report they cannot be closed, i.e. if can_delete_all_plugins() returns False.

Returns:

all_deletedTrue if all the plugins were deleted. False otherwise.

Return type:

bool

get_plugin(plugin_name: str) spyder.api.plugin_registration.registry.SpyderPluginClass[source]#

Get a reference to a plugin instance by its name.

Parameters:

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

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) None[source]#

Add a plugin by name to the set of enabled plugins.

Parameters:

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

Return type:

None

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 check.

Returns:

plugin_enabledTrue 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 is loaded and ready for use.

Parameters:

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

Returns:

plugin_availableTrue if the plugin is available and False if not.

Return type:

bool

reset() None[source]#

Reset and empty the plugin registry.

Return type:

None

set_all_internal_plugins(all_plugins: dict[str, tuple[str, type[spyder.api.plugin_registration.registry.SpyderPluginClass]]]) None[source]#

Set the all_internal_plugins attribute to the given plugins.

Deprecated since version 6.2: Will raise a DeprecationWarning in Spyder 6.2 and be removed in Spyder 7.0. Set the all_internal_plugins attribute directly instead.

Parameters:

all_plugins (dict[str, tuple[str, type[SpyderPluginClass]]]) – Mapping of plugin name to plugin class to set the attribute to.

Return type:

None

set_all_external_plugins(all_plugins: dict[str, tuple[str, type[spyder.api.plugin_registration.registry.SpyderPluginClass]]]) None[source]#

Set the all_external_plugins attribute to the given plugins.

Deprecated since version 6.2: Will raise a DeprecationWarning in Spyder 6.2 and be removed in Spyder 7.0. Set the all_external_plugins attribute directly instead.

Parameters:

all_plugins (dict[str, tuple[str, type[SpyderPluginClass]]]) – Mapping of plugin name to plugin class to set the attribute to.

Return type:

None

set_main(main: spyder.app.mainwindow.MainWindow) None[source]#

Set the reference to the Spyder main window for the plugin registry.

Deprecated since version 6.2: Will raise a DeprecationWarning in Spyder 6.2 and be removed in Spyder 7.0. Set the main attribute directly instead.

Parameters:

main (spyder.app.mainwindow.MainWindow) – The Spyder main window instance to set the reference to.

Return type:

None

get_icon() QIcon[source]#

Icon of the plugin registry, for use in the Spyder interface.

get_name() str[source]#

Name of the plugin registry, translated to the locale language.

__contains__(plugin_name: str) bool[source]#

Determine if a plugin with a given name is contained in the registry.

Parameters:

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

Returns:

is_contained – If True, plugin_name is contained in the registry; False otherwise.

Return type:

bool

spyder.api.plugin_registration.registry.PLUGIN_REGISTRY: SpyderPluginRegistry = <spyder.api.plugin_registration.registry.SpyderPluginRegistry object>#

The global Spyder plugin registry instance.