Skip to content

Commit

Permalink
API: Add error kwarg to get_plugin method
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Aug 26, 2022
1 parent 45de2d4 commit cae2a7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions spyder/api/plugins/new_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,17 @@ def get_main(self):
"""
return self._main

def get_plugin(self, plugin_name):
def get_plugin(self, plugin_name, error=True):
"""
Return a plugin instance by providing the plugin's NAME.
Get a plugin instance by providing its name.
Parameters
----------
plugin_name: str
Name of the plugin from which its instance will be returned.
error: bool
Whether to raise errors when trying to return the plugin's
instance.
"""
# Ensure that this plugin has the plugin corresponding to
# `plugin_name` listed as required or optional.
Expand All @@ -416,7 +424,7 @@ def get_plugin(self, plugin_name):

if plugin_name in full_set or Plugins.All in full_set:
try:
return self._main.get_plugin(plugin_name)
return self._main.get_plugin(plugin_name, error=error)
except SpyderAPIError as e:
if plugin_name in optional:
return None
Expand Down
4 changes: 2 additions & 2 deletions spyder/plugins/layout/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def restore_visible_plugins(self):

# Restore visible plugins
for plugin in visible_plugins:
plugin_class = self.main.get_plugin(plugin, error=False)
plugin_class = self.get_plugin(plugin, error=False)
if plugin_class and plugin_class.dockwidget.isVisible():
plugin_class.dockwidget.raise_()

Expand Down Expand Up @@ -1084,7 +1084,7 @@ def tabify_new_plugins(self):
# Tabify new internal plugins
for plugin_name in self._get_internal_dockable_plugins():
if plugin_name not in last_internal_dockable_plugins:
plugin = self.main.get_plugin(plugin_name, error=False)
plugin = self.get_plugin(plugin_name, error=False)
if plugin:
self.tabify_plugin(plugin, Plugins.Console)

Expand Down

0 comments on commit cae2a7b

Please sign in to comment.