Commit 632a7d80 by finswimmer

feat!: drop deprecated `plugin` command

parent 5f8b9da1
...@@ -78,10 +78,6 @@ COMMANDS = [ ...@@ -78,10 +78,6 @@ COMMANDS = [
"env list", "env list",
"env remove", "env remove",
"env use", "env use",
# Plugin commands
"plugin add",
"plugin remove",
"plugin show",
# Self commands # Self commands
"self add", "self add",
"self install", "self install",
......
from __future__ import annotations
from cleo.helpers import argument
from cleo.helpers import option
from cleo.io.inputs.string_input import StringInput
from cleo.io.io import IO
from poetry.console.commands.init import InitCommand
from poetry.console.commands.self.add import SelfAddCommand
class PluginAddCommand(InitCommand):
name = "plugin add"
description = "Adds new plugins."
arguments = [
argument("plugins", "The names of the plugins to install.", multiple=True),
]
options = [
option(
"dry-run",
None,
"Output the operations but do not execute anything (implicitly enables"
" --verbose).",
)
]
deprecation = (
"<warning>This command is deprecated. Use <c2>self add</> command instead."
"</warning>"
)
help = f"""
The <c1>plugin add</c1> command installs Poetry plugins globally.
It works similarly to the <c1>add</c1> command:
{SelfAddCommand.examples}
{deprecation}
"""
hidden = True
def handle(self) -> int:
self.line_error(self.deprecation)
application = self.get_application()
command = application.find("self add")
assert isinstance(command, SelfAddCommand)
application.configure_installer_for_command(command, self.io)
argv: list[str] = ["add", *self.argument("plugins")]
if self.option("--dry-run"):
argv.append("--dry-run")
exit_code: int = command.run(
IO(
StringInput(" ".join(argv)),
self.io.output,
self.io.error_output,
)
)
return exit_code
from __future__ import annotations
from cleo.helpers import argument
from cleo.helpers import option
from cleo.io.inputs.string_input import StringInput
from cleo.io.io import IO
from poetry.console.commands.command import Command
from poetry.console.commands.self.remove import SelfRemoveCommand
class PluginRemoveCommand(Command):
name = "plugin remove"
description = "Removes installed plugins"
arguments = [
argument("plugins", "The names of the plugins to install.", multiple=True),
]
options = [
option(
"dry-run",
None,
"Output the operations but do not execute anything (implicitly enables"
" --verbose).",
)
]
help = (
"<warning>This command is deprecated. Use <c2>self remove</> command instead."
"</warning>"
)
hidden = True
def handle(self) -> int:
self.line_error(self.help)
application = self.get_application()
command = application.find("self remove")
assert isinstance(command, SelfRemoveCommand)
application.configure_installer_for_command(command, self.io)
argv: list[str] = ["remove", *self.argument("plugins")]
if self.option("--dry-run"):
argv.append("--dry-run")
exit_code: int = command.run(
IO(
StringInput(" ".join(argv)),
self.io.output,
self.io.error_output,
)
)
return exit_code
from __future__ import annotations
from cleo.io.inputs.string_input import StringInput
from cleo.io.io import IO
from poetry.console.commands.command import Command
class PluginShowCommand(Command):
name = "plugin show"
description = "Shows information about the currently installed plugins."
help = (
"<warning>This command is deprecated. Use <c2>self show plugins</> "
"command instead.</warning>"
)
hidden = True
def handle(self) -> int:
self.line_error(self.help)
application = self.get_application()
command = application.find("self show plugins")
exit_code: int = command.run(
IO(
StringInput(""),
self.io.output,
self.io.error_output,
)
)
return exit_code
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
from poetry.core.packages.package import Package
from poetry.__version__ import __version__
if TYPE_CHECKING:
from cleo.testers.command_tester import CommandTester
from tests.helpers import TestRepository
from tests.types import CommandTesterFactory
@pytest.fixture()
def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return command_tester_factory("plugin add")
def test_deprecation_warning(tester: CommandTester, repo: TestRepository) -> None:
repo.add_package(Package("poetry", __version__))
repo.add_package(Package("poetry-plugin", "1.0"))
tester.execute("poetry-plugin")
assert (
tester.io.fetch_error()
== "This command is deprecated. Use self add command instead.\n"
)
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.package import Package
from poetry.core.packages.project_package import ProjectPackage
from poetry.__version__ import __version__
from poetry.console.commands.self.self_command import SelfCommand
from poetry.factory import Factory
from tests.console.commands.self.utils import get_self_command_dependencies
if TYPE_CHECKING:
from cleo.testers.command_tester import CommandTester
from tests.helpers import TestRepository
from tests.types import CommandTesterFactory
@pytest.fixture()
def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return command_tester_factory("plugin remove")
def test_deprecation_warning(tester: CommandTester, repo: TestRepository) -> None:
plugin = Package("poetry-plugin", "1.2.3")
repo.add_package(Package("poetry", __version__))
repo.add_package(plugin)
package = ProjectPackage("poetry-instance", __version__)
package.add_dependency(
Dependency(plugin.name, "^1.2.3", groups=[SelfCommand.ADDITIONAL_PACKAGE_GROUP])
)
content = Factory.create_pyproject_from_package(package)
system_pyproject_file = SelfCommand.get_default_system_pyproject_file()
system_pyproject_file.write_text(content.as_string(), encoding="utf-8")
dependencies = get_self_command_dependencies(locked=False)
assert "poetry-plugin" in dependencies
tester.execute("poetry-plugin")
assert (
tester.io.fetch_error()
== "This command is deprecated. Use self remove command instead.\n"
)
dependencies = get_self_command_dependencies()
assert "poetry-plugin" not in dependencies
assert not dependencies
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
if TYPE_CHECKING:
from cleo.testers.command_tester import CommandTester
from tests.types import CommandTesterFactory
@pytest.fixture()
def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return command_tester_factory("plugin show")
def test_deprecation_warning(tester: CommandTester) -> None:
tester.execute("")
assert (
tester.io.fetch_error()
== "This command is deprecated. Use self show plugins command instead.\n"
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment