Skip to content

Commit

Permalink
Add utility for retrieving the name of all shimmed plugins (#372)
Browse files Browse the repository at this point in the history
Adds a simple utility that iterates through all discovered plugins and
returns the names of all plugins that are shimmed from `npe1` i.e. don't
have their own manifest, but have an `npe1` entrypoint.

---------

Co-authored-by: Juan Nunez-Iglesias <[email protected]>
  • Loading branch information
DragaDoncila and jni authored Jan 22, 2025
1 parent 40a4677 commit 874d809
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/npe2/_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,10 @@ def get_writer(
# Nothing got found
return None, path

def get_shimmed_plugins(self) -> List[str]:
"""Return a list of all shimmed plugin names."""
return [mf.name for mf in self.iter_manifests() if mf.npe1_shim]


class PluginContext:
"""An object that can contain information for a plugin over its lifetime."""
Expand Down
4 changes: 4 additions & 0 deletions src/npe2/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def get_writer(
"""Get Writer contribution appropriate for `path`, and `layer_types`."""


def get_shimmed_plugins() -> List[str]:
"""Return a list of all shimmed plugin names."""


def _populate_module():
"""Convert all functions in this module into global plugin manager methods."""
import functools
Expand Down
8 changes: 8 additions & 0 deletions tests/test_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,11 @@ def test_command_menu_map(uses_sample_plugin, plugin_manager: PluginManager):
assert SAMPLE_PLUGIN_NAME not in pm._command_menu_map
pm.register(SAMPLE_PLUGIN_NAME)
assert SAMPLE_PLUGIN_NAME in pm._command_menu_map


def test_get_shimmed_plugins(pm: PluginManager, uses_npe1_plugin):
assert len(pm.get_shimmed_plugins()) == 0
pm.discover(include_npe1=True)
shimmed = pm.get_shimmed_plugins()
assert len(shimmed) == 1
assert shimmed[0] == "npe1-plugin"

0 comments on commit 874d809

Please sign in to comment.