Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Don't double validate if plugins can be deleted/closed (Registry) #18625

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions spyder/api/plugin_registration/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ def dock_undocked_plugin(
# Close undocked plugins.
plugin_instance._close_window()

def delete_plugin(self, plugin_name: str, teardown: bool = True) -> bool:
def delete_plugin(self, plugin_name: str, teardown: bool = True,
check_can_delete: bool = True) -> bool:
"""
Remove and delete a plugin from the registry by its name.

Expand All @@ -457,6 +458,9 @@ def delete_plugin(self, plugin_name: str, teardown: bool = True) -> bool:
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
-------
Expand All @@ -468,9 +472,10 @@ def delete_plugin(self, plugin_name: str, teardown: bool = True) -> bool:
plugin_instance = self.plugin_registry[plugin_name]

# Determine if plugin can be closed
can_delete = self.can_delete_plugin(plugin_name)
if not can_delete:
return False
if check_can_delete:
can_delete = self.can_delete_plugin(plugin_name)
if not can_delete:
return False

if isinstance(plugin_instance, SpyderPluginV2):
# Cleanly delete plugin widgets. This avoids segfautls with
Expand Down Expand Up @@ -637,7 +642,7 @@ def delete_all_plugins(self, excluding: Optional[Set[str]] = None,
plugin_instance = self.plugin_registry[plugin_name]
if isinstance(plugin_instance, SpyderPlugin):
can_close &= self.delete_plugin(
plugin_name, teardown=False)
plugin_name, teardown=False, check_can_delete=False)
if not can_close and not close_immediately:
break

Expand All @@ -650,7 +655,7 @@ def delete_all_plugins(self, excluding: Optional[Set[str]] = None,
plugin_instance = self.plugin_registry[plugin_name]
if isinstance(plugin_instance, SpyderPlugin):
can_close &= self.delete_plugin(
plugin_name, teardown=False)
plugin_name, teardown=False, check_can_delete=False)
if not can_close and not close_immediately:
break

Expand All @@ -663,7 +668,7 @@ def delete_all_plugins(self, excluding: Optional[Set[str]] = None,
plugin_instance = self.plugin_registry[plugin_name]
if isinstance(plugin_instance, SpyderPluginV2):
can_close &= self.delete_plugin(
plugin_name, teardown=False)
plugin_name, teardown=False, check_can_delete=False)
if not can_close and not close_immediately:
break

Expand All @@ -676,7 +681,7 @@ def delete_all_plugins(self, excluding: Optional[Set[str]] = None,
plugin_instance = self.plugin_registry[plugin_name]
if isinstance(plugin_instance, SpyderPluginV2):
can_close &= self.delete_plugin(
plugin_name, teardown=False)
plugin_name, teardown=False, check_can_delete=False)
if not can_close and not close_immediately:
break

Expand Down