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

Add enable disable #101

Merged
merged 15 commits into from
Feb 15, 2022
Merged

Add enable disable #101

merged 15 commits into from
Feb 15, 2022

Conversation

tlambert03
Copy link
Collaborator

@tlambert03 tlambert03 commented Feb 13, 2022

This adds:

  • PluginManager.enable
  • PluginManager.disable

and new signals:

  • PluginManager.events.plugins_registered
  • PluginManager.events.activation_changed
  • PluginManager.events.enablement_changed

_ContributionsIndex has been minimized, but not completely removed, and gains a remove_contributions method

ALSO: note that this removes discover() from the init method. So it must be called manually

see also napari/napari#4086

I'm also taking the opportunity to re-order the methods and add docstrings on PluginManager (so the number of lines in this PR looks higher than it really is). They're starting to get scattered about without much logic

@codecov
Copy link

codecov bot commented Feb 13, 2022

Codecov Report

Merging #101 (82301dd) into main (0cb4f03) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #101   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         1282      1347   +65     
=========================================
+ Hits          1282      1347   +65     
Impacted Files Coverage Δ
npe2/_plugin_manager.py 100.00% <100.00%> (ø)
npe2/manifest/schema.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0cb4f03...82301dd. Read the comment docs.

@tlambert03
Copy link
Collaborator Author

this is all set @nclack

Copy link
Collaborator

@nclack nclack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Made a few small suggestions.

npe2/manifest/schema.py Outdated Show resolved Hide resolved
npe2/_plugin_manager.py Show resolved Hide resolved
npe2/_plugin_manager.py Show resolved Hide resolved
tests/sample/my_plugin/napari.yaml Show resolved Hide resolved
npe2/_plugin_manager.py Show resolved Hide resolved
npe2/_plugin_manager.py Outdated Show resolved Hide resolved
npe2/_plugin_manager.py Outdated Show resolved Hide resolved
tlambert03 and others added 3 commits February 14, 2022 22:41
Co-authored-by: Nathan Clack <nclack@gmail.com>
Co-authored-by: Nathan Clack <nclack@gmail.com>
Co-authored-by: Nathan Clack <nclack@gmail.com>
@tlambert03 tlambert03 closed this Feb 15, 2022
@tlambert03 tlambert03 reopened this Feb 15, 2022

def disable(self, plugin_name: PluginName) -> None:
"""Disable a plugin"""
self._disabled_plugins.add(plugin_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to to do the same check that a plugin is not already disabled, even if remove_contributions is no-op for consistency whether self.events.enablement_changed is emited.

npe2/_plugin_manager.py Outdated Show resolved Hide resolved
def discover(self, paths: Sequence[str] = ()) -> None:
# Discovery, activation, enablement

def discover(self, paths: Sequence[str] = (), clear=False) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe technically the super class also allows Path in addition to strings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. I think we want to remove discover from PluginManifest altogether and move that logic here. so might do in a followup pr

self._manifests.clear()
if clear:
self._contrib = _ContributionsIndex()
self._manifests.clear()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not evented (I think ?) so you can also just assign an empty dict ? Would it be faster ? Unless something else keep reference to _manifest ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm trying to keep all private access within classes, even within npe2, so it should be fine just to set to empty dict

Comment on lines +99 to +102
for contribs in self._readers.values():
for i, ctrb in reversed(list(enumerate(contribs))):
if ctrb.plugin_name == key:
contribs.pop(i)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we starting to make things really complicated using dicts, instead of using something flatter, and filtering in the relevant methods ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps! not married at all to this one if you want to propose a better structure

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let' try to finish that and I'll suggest a refactor.

Co-authored-by: Matthias Bussonnier <bussonniermatthias@gmail.com>
@tlambert03 tlambert03 merged commit 53a91ca into napari:main Feb 15, 2022
@tlambert03 tlambert03 deleted the enable-disable branch February 15, 2022 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants