|
1 | 1 | import sys |
| 2 | +from importlib.metadata import EntryPoint |
| 3 | +from importlib.metadata import distribution as importlib_distribution |
2 | 4 | from importlib.metadata import entry_points |
3 | 5 |
|
4 | 6 | import typer # type: ignore[import] |
@@ -29,16 +31,29 @@ def callback( |
29 | 31 | pass |
30 | 32 |
|
31 | 33 |
|
| 34 | +def entrypoint_to_pkgname(entrypoint: EntryPoint) -> str: |
| 35 | + """Find package name from entrypoint""" |
| 36 | + |
| 37 | + top_level = entrypoint.value.split(".")[0] |
| 38 | + dist = importlib_distribution(top_level) |
| 39 | + return dist.metadata["name"] |
| 40 | + |
| 41 | + |
32 | 42 | def register_plugins(): |
33 | 43 | """Register subcommands via the ``pyodide.cli`` entry-point""" |
34 | 44 | eps = entry_points(group="pyodide.cli") |
35 | | - plugins = {ep.name: ep.load() for ep in eps} |
36 | | - for plugin_name, module in plugins.items(): |
| 45 | + plugins = {ep.name: (ep.load(), ep) for ep in eps} |
| 46 | + for plugin_name, (module, ep) in plugins.items(): |
| 47 | + pkgname = entrypoint_to_pkgname(ep) |
37 | 48 | if isinstance(module, typer.Typer): |
38 | | - app.add_typer(module, name=plugin_name) |
| 49 | + app.add_typer( |
| 50 | + module, name=plugin_name, rich_help_panel=f"Registered by: {pkgname}" |
| 51 | + ) |
39 | 52 | elif callable(module): |
40 | 53 | typer_kwargs = getattr(module, "typer_kwargs", {}) |
41 | | - app.command(plugin_name, **typer_kwargs)(module) |
| 54 | + app.command( |
| 55 | + plugin_name, rich_help_panel=f"Registered by: {pkgname}", **typer_kwargs |
| 56 | + )(module) |
42 | 57 | else: |
43 | 58 | raise RuntimeError(f"Invalid plugin: {plugin_name}") |
44 | 59 |
|
|
0 commit comments