spyder.api.plugin_registration.decorators#
Spyder API plugin registration decorators.
Functions
|
Decorate a method to be called back when a specific plugin becomes ready. |
|
Decorate a method to be called back when tearing down a specific plugin. |
- spyder.api.plugin_registration.decorators.on_plugin_available(func: Callable | None = None, plugin: str | None = None) Callable[source]#
Decorate a method to be called back when a specific plugin becomes ready.
The decorated method must be a member of a
SpyderPluginV2subclass for the decorator to work as intended.Methods to be decorated must have the signature
def method(self): ...
when observing a single plugin, or
def method(self, plugin: str): ...
when observing all plugins listed as dependencies.
Caution
Any
plugin(s) specified must be listed under either theREQUIRESorOPTIONALclass constants of the plugin’sSpyderPluginV2class. If not, aSpyderAPIErrorwill be raised when the plugin class is initialized.- Parameters:
func (Callable | None, optional) – Method to decorate, passed automatically when applying the decorator.
plugin (str | None, optional) – Name of the requested plugin whose availability triggers
func. IfNone(the default), observes all plugins listed as dependencies. Must be listed under the class’ ‘REQUIRESorOPTIONALclass constants, or else aSpyderAPIErrorwill be raised.
- Returns:
func – The method passed as
funcwith the plugin listener set up.- Return type:
Callable
- Raises:
SpyderAPIError – When initializing a plugin class with decorated methods, if trying to watch a
pluginthat is not listed in the plugin class’REQUIRESorOPTIONALclass constants.
- spyder.api.plugin_registration.decorators.on_plugin_teardown(func: Callable | None = None, plugin: str | None = None) Callable[source]#
Decorate a method to be called back when tearing down a specific plugin.
The decorated method must be a member of a
SpyderPluginV2subclass for the decorator to work as intended.The decorator will be called before the specified
pluginis deleted and also before the plugin that uses the decorator is destroyed.Methods that use this decorator must have the signature
def method(self): ...
Important
A plugin name must be passed to
plugin. While a default ofNoneis accepted due to technical limitations, it will raise aValueErrorat runtime.Caution
Any
plugin(s) specified must be listed under either theREQUIRESorOPTIONALclass constants of the plugin’sSpyderPluginV2class. If not, aSpyderAPIErrorwill be raised when the plugin class is initialized.- Parameters:
func (Callable | None, optional) – Method to decorate, passed automatically when applying the decorator.
plugin (str) – Name of the requested plugin whose teardown triggers
func. WhileNone, the default, is accepted for technical reasons,ValueErroris raised if a plugin name is not passed. Must be listed under the class’ ‘REQUIRESorOPTIONALclass constants, or else aSpyderAPIErrorwill be raised.
- Returns:
func – The method passed as
funcwith the plugin listener set up.- Return type:
Callable
- Raises:
ValueError – If an explicit plugin name is not passed to
plugin.SpyderAPIError – When initializing a plugin class with decorated methods, if trying to watch a
pluginthat is not listed in the plugin class’REQUIRESorOPTIONALclass constants.