Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 0 additions & 22 deletions pyodide_cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import click
import typer
from typer.main import solve_typer_info_help
from typer.models import TyperInfo

from . import __version__

Expand Down Expand Up @@ -147,29 +145,13 @@ def _entrypoint_to_version(entrypoint: EntryPoint) -> str:
return dist.metadata["version"]


def _inject_origin(docstring: str, origin: str) -> str:
return f"{docstring}\n\n{origin}"


def register_plugins():
"""Register subcommands via the ``pyodide.cli`` entry-point"""
eps = entry_points(group="pyodide.cli")
plugins = {ep.name: (ep.load(), ep) for ep in eps}

for plugin_name, (module, ep) in plugins.items():
pkgname = _entrypoint_to_pkgname(ep)
origin_text = f"Registered by {pkgname}:"

if isinstance(module, typer.Typer):
typer_info = TyperInfo(module)
help_with_origin = _inject_origin(
solve_typer_info_help(typer_info), origin_text
)
else:
help_with_origin = _inject_origin(
getattr(module, "__doc__", ""), origin_text
)

if isinstance(module, click.Command):
cmd = module
elif isinstance(module, typer.Typer):
Expand All @@ -179,16 +161,12 @@ def register_plugins():
app = typer.Typer()
app.command(
plugin_name,
help=help_with_origin,
**typer_kwargs,
)(module)
cmd = typer.main.get_command(app)
else:
raise RuntimeError(f"Invalid plugin: {plugin_name}")

# directly manipulate click Command help message
cmd.help = help_with_origin

cli.add_command(cmd, name=plugin_name, origin=pkgname)


Expand Down
10 changes: 0 additions & 10 deletions pyodide_cli/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,3 @@ def test_plugin_origin(plugins):
msg = "Registered by plugin-test:"

assert msg in output


@pytest.mark.parametrize(
"entrypoint", ["plugin_test_app", "plugin_test_func", "plugin_test_cli"]
)
def test_plugin_origin_subcommand(plugins, entrypoint):
output = check_output(["pyodide", entrypoint, "--help"]).decode("utf-8")
msg = "Registered by plugin-test:"

assert msg in output