npe2 0.7.5rc0__py3-none-any.whl → 0.7.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
npe2/_plugin_manager.py CHANGED
@@ -4,7 +4,7 @@ import contextlib
4
4
  import os
5
5
  import urllib
6
6
  import warnings
7
- from collections import Counter
7
+ from collections import Counter, defaultdict
8
8
  from fnmatch import fnmatch
9
9
  from importlib import metadata
10
10
  from logging import getLogger
@@ -38,6 +38,7 @@ from .types import PathLike, PythonName
38
38
  if TYPE_CHECKING:
39
39
  from .manifest.contributions import (
40
40
  CommandContribution,
41
+ MenuCommand,
41
42
  MenuItem,
42
43
  ReaderContribution,
43
44
  SampleDataContribution,
@@ -235,6 +236,9 @@ class PluginManager:
235
236
  self._manifests: Dict[PluginName, PluginManifest] = {}
236
237
  self.events = PluginManagerEvents(self)
237
238
  self._npe1_adapters: List[NPE1Adapter] = []
239
+ self._command_menu_map: Dict[
240
+ str, Dict[str, Dict[str, List[MenuCommand]]]
241
+ ] = defaultdict(dict)
238
242
 
239
243
  # up to napari 0.4.15, discovery happened in the init here
240
244
  # so if we're running on an older version of napari, we need to discover
@@ -358,14 +362,28 @@ class PluginManager:
358
362
  self._npe1_adapters.append(manifest)
359
363
  else:
360
364
  self._contrib.index_contributions(manifest)
365
+ self._populate_command_menu_map(manifest)
361
366
  self.events.plugins_registered.emit({manifest})
362
367
 
368
+ def _populate_command_menu_map(self, manifest: PluginManifest):
369
+ # map of manifest -> command -> menu_id -> list[items]
370
+ self._command_menu_map[manifest.name] = defaultdict(lambda: defaultdict(list))
371
+ menu_map = self._command_menu_map[manifest.name] # just for conciseness below
372
+ for menu_id, menu_items in manifest.contributions.menus.items() or ():
373
+ # command IDs are keys in map
374
+ # each value is a dict menu_id: list of MenuCommands
375
+ # for the command and menu
376
+ for item in menu_items:
377
+ if (command_id := getattr(item, "command", None)) is not None:
378
+ menu_map[command_id][menu_id].append(item)
379
+
363
380
  def unregister(self, key: PluginName):
364
381
  """Unregister plugin named `key`."""
365
382
  if key not in self._manifests:
366
383
  raise ValueError(f"No registered plugin named {key!r}") # pragma: no cover
367
384
  self.deactivate(key)
368
385
  self._contrib.remove_contributions(key)
386
+ self._command_menu_map.pop(key)
369
387
  self._manifests.pop(key)
370
388
 
371
389
  def activate(self, key: PluginName) -> PluginContext:
@@ -448,6 +466,7 @@ class PluginManager:
448
466
  mf = self._manifests.get(plugin_name)
449
467
  if mf is not None:
450
468
  self._contrib.index_contributions(mf)
469
+ self._populate_command_menu_map(mf)
451
470
  self.events.enablement_changed({plugin_name}, {})
452
471
 
453
472
  def disable(self, plugin_name: PluginName) -> None:
@@ -467,6 +486,7 @@ class PluginManager:
467
486
 
468
487
  self._disabled_plugins.add(plugin_name)
469
488
  self._contrib.remove_contributions(plugin_name)
489
+ self._command_menu_map.pop(plugin_name, None)
470
490
  self.events.enablement_changed({}, {plugin_name})
471
491
 
472
492
  def is_disabled(self, plugin_name: str) -> bool:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: npe2
3
- Version: 0.7.5rc0
3
+ Version: 0.7.7
4
4
  Summary: napari plugin engine v2
5
5
  Project-URL: homepage, https://github.com/napari/npe2
6
6
  Project-URL: repository, https://github.com/napari/npe2
@@ -2,7 +2,7 @@ npe2/__init__.py,sha256=2yMcClmts4aO-1qQR80J_XOcx_fiXXhPHxx6BYlvG3s,812
2
2
  npe2/__main__.py,sha256=NwbyYIU4bE1YPADH6zxLF3i7_51oELpK1UXz6141iwE,65
3
3
  npe2/_command_registry.py,sha256=-L2QLeikqcFalIk-tZgqkgEGjHUCZpm5cIGP0TxzoN8,5056
4
4
  npe2/_dynamic_plugin.py,sha256=Y_kduq8YlyF9QrNVhGbMihlaBqeoww1HXvg456jpaww,10040
5
- npe2/_plugin_manager.py,sha256=6HzS9SVx0CkQTIoJ0zTnWe9Aew72aI-aADOLprEkjKI,29071
5
+ npe2/_plugin_manager.py,sha256=vhG_4988gXv2AVMWVw6_RDo15BYgjqau0izyJuZWdmI,30135
6
6
  npe2/_pydantic_compat.py,sha256=RpUWS_pVOAx2pbNgZvdxsZtXxR5igZA2jsSQzTWtYNU,1152
7
7
  npe2/_pytest_plugin.py,sha256=Dw73_eHFoBT_mivmFzr73ZGwBe1wwoSb790Mk1QlKn8,3610
8
8
  npe2/_setuptools_plugin.py,sha256=85tFOTmGAMeMDcPYmT3HvadPsQSAKLrAt63BhYmJQxk,6785
@@ -42,8 +42,8 @@ npe2/manifest/contributions/_submenu.py,sha256=pjHZbfn5iCQBwNaTIGMWHNNswtSPLlnml
42
42
  npe2/manifest/contributions/_themes.py,sha256=FeHBeqayZOIN4ccyik1xPZ30cE-_3Xr7aozilyoamiY,2683
43
43
  npe2/manifest/contributions/_widgets.py,sha256=ung4t6R4EB6Rz9Xmlb4Z46ilOHHmkoWkEMuHQC4kABw,2217
44
44
  npe2/manifest/contributions/_writers.py,sha256=i1usy_tR_1XIf93c8HXu0APLJI3QrOJUc0-0nxLrLbI,7867
45
- npe2-0.7.5rc0.dist-info/METADATA,sha256=FzEA-khJ86DwtlkTsAebj4BQgFvEiXw6aEQnQ8rfsRY,3098
46
- npe2-0.7.5rc0.dist-info/WHEEL,sha256=bq9SyP5NxIRA9EpQgMCd-9RmPHWvbH-4lTDGwxgIR64,87
47
- npe2-0.7.5rc0.dist-info/entry_points.txt,sha256=5zoegMudO8Hkn6589GlAXIW49Ar5HSWZjTRc0TkJu3s,250
48
- npe2-0.7.5rc0.dist-info/licenses/LICENSE,sha256=uyX2Y2Q7D-WzOUc6EKZVDuadkWenBWSYTR--BsewGpg,1514
49
- npe2-0.7.5rc0.dist-info/RECORD,,
45
+ npe2-0.7.7.dist-info/METADATA,sha256=LCNfwgBkYvgtwnG12ab5BPCUjz9pU1CzLAxV9BnrKnc,3095
46
+ npe2-0.7.7.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
47
+ npe2-0.7.7.dist-info/entry_points.txt,sha256=5zoegMudO8Hkn6589GlAXIW49Ar5HSWZjTRc0TkJu3s,250
48
+ npe2-0.7.7.dist-info/licenses/LICENSE,sha256=uyX2Y2Q7D-WzOUc6EKZVDuadkWenBWSYTR--BsewGpg,1514
49
+ npe2-0.7.7.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.22.3
2
+ Generator: hatchling 1.25.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any