Skip to content

Commit

Permalink
cmd/plugin/show: use entrypoint distro name
Browse files Browse the repository at this point in the history
Prior to this change the `plugin show` command assumed the entrypoint
name to be the same as the package providing the plugin. This change
makes use of the `entrypoint.distro.name` instead to derive the source
package.

Resolves: python-poetry#5417
  • Loading branch information
abn committed Apr 6, 2022
1 parent 748b1c6 commit 96f7930
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/poetry/console/commands/plugin/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def handle(self) -> int:
if issubclass(plugin, ApplicationPlugin):
category = "application_plugins"

package = packages_by_name[canonicalize_name(entry_point.name)]
package = packages_by_name[canonicalize_name(entry_point.distro.name)]
plugins[package.pretty_name]["package"] = package
plugins[package.pretty_name][category].append(entry_point)

Expand Down
42 changes: 34 additions & 8 deletions tests/console/commands/plugin/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from entrypoints import Distribution
from entrypoints import EntryPoint as _EntryPoint
from poetry.core.packages.package import Package

Expand Down Expand Up @@ -35,33 +36,49 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return command_tester_factory("plugin show")


@pytest.fixture()
def plugin_package() -> Package:
return Package("poetry-plugin", "1.2.3")


@pytest.fixture()
def plugin_distro(plugin_package: Package) -> Distribution:
return Distribution(plugin_package.name, plugin_package.version.to_string(True))


@pytest.mark.parametrize("entrypoint_name", ["poetry-plugin", "not-package-name"])
def test_show_displays_installed_plugins(
app: PoetryTestApplication,
tester: CommandTester,
installed: Repository,
mocker: MockerFixture,
plugin_package: Package,
plugin_distro: Distribution,
entrypoint_name: str,
):
mocker.patch(
"entrypoints.get_group_all",
side_effect=[
[
EntryPoint(
"poetry-plugin",
entrypoint_name,
"poetry_plugin.plugins:ApplicationPlugin",
"FirstApplicationPlugin",
distro=plugin_distro,
)
],
[
EntryPoint(
"poetry-plugin",
entrypoint_name,
"poetry_plugin.plugins:Plugin",
"FirstPlugin",
distro=plugin_distro,
)
],
],
)

installed.add_package(Package("poetry-plugin", "1.2.3"))
installed.add_package(plugin_package)

tester.execute("")

Expand All @@ -78,6 +95,8 @@ def test_show_displays_installed_plugins_with_multiple_plugins(
tester: CommandTester,
installed: Repository,
mocker: MockerFixture,
plugin_package: Package,
plugin_distro: Distribution,
):
mocker.patch(
"entrypoints.get_group_all",
Expand All @@ -87,29 +106,33 @@ def test_show_displays_installed_plugins_with_multiple_plugins(
"poetry-plugin",
"poetry_plugin.plugins:ApplicationPlugin",
"FirstApplicationPlugin",
distro=plugin_distro,
),
EntryPoint(
"poetry-plugin",
"poetry_plugin.plugins:ApplicationPlugin",
"SecondApplicationPlugin",
distro=plugin_distro,
),
],
[
EntryPoint(
"poetry-plugin",
"poetry_plugin.plugins:Plugin",
"FirstPlugin",
distro=plugin_distro,
),
EntryPoint(
"poetry-plugin",
"poetry_plugin.plugins:Plugin",
"SecondPlugin",
distro=plugin_distro,
),
],
],
)

installed.add_package(Package("poetry-plugin", "1.2.3"))
installed.add_package(plugin_package)

tester.execute("")

Expand All @@ -126,6 +149,8 @@ def test_show_displays_installed_plugins_with_dependencies(
tester: CommandTester,
installed: Repository,
mocker: MockerFixture,
plugin_package: Package,
plugin_distro: Distribution,
):
mocker.patch(
"entrypoints.get_group_all",
Expand All @@ -135,22 +160,23 @@ def test_show_displays_installed_plugins_with_dependencies(
"poetry-plugin",
"poetry_plugin.plugins:ApplicationPlugin",
"FirstApplicationPlugin",
distro=plugin_distro,
)
],
[
EntryPoint(
"poetry-plugin",
"poetry_plugin.plugins:Plugin",
"FirstPlugin",
distro=plugin_distro,
)
],
],
)

plugin = Package("poetry-plugin", "1.2.3")
plugin.add_dependency(Factory.create_dependency("foo", ">=1.2.3"))
plugin.add_dependency(Factory.create_dependency("bar", "<4.5.6"))
installed.add_package(plugin)
plugin_package.add_dependency(Factory.create_dependency("foo", ">=1.2.3"))
plugin_package.add_dependency(Factory.create_dependency("bar", "<4.5.6"))
installed.add_package(plugin_package)

tester.execute("")

Expand Down

0 comments on commit 96f7930

Please sign in to comment.