Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def _load() -> Command:
"source show",
]

VERSION_OPTIONS = ["--version", "-V"]

# these are special messages to override the default message when a command is not found
# in cases where a previously existing command has been moved to a plugin or outright
# removed for various reasons
Expand Down Expand Up @@ -626,7 +628,7 @@ def _load_plugins(self, io: IO) -> None:

self._disable_plugins = io.input.has_parameter_option("--no-plugins")

if not self._disable_plugins:
if self._should_load_plugins(io):
from poetry.plugins.application_plugin import ApplicationPlugin
from poetry.plugins.plugin_manager import PluginManager

Expand All @@ -637,6 +639,11 @@ def _load_plugins(self, io: IO) -> None:

self._plugins_loaded = True

def _should_load_plugins(self, io: IO) -> bool:
return not self._disable_plugins and not io.input.has_parameter_option(
VERSION_OPTIONS, only_params=True
)


def main() -> int:
exit_code: int = Application().run()
Expand Down
23 changes: 21 additions & 2 deletions tests/console/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ def test_application_with_plugins_disabled(with_add_command_plugin: None) -> Non
assert tester.status_code == 0


@pytest.mark.parametrize("version_option", ["--version", "-V"])
def test_application_version_does_not_load_plugins(
version_option: str, mocker: MockerFixture
) -> None:
load_plugins = mocker.patch(
"poetry.plugins.plugin_manager.PluginManager.load_plugins"
)
activate = mocker.patch("poetry.plugins.plugin_manager.PluginManager.activate")
app = Application()

tester = ApplicationTester(app)
tester.execute(version_option)

assert "Poetry (version " in tester.io.fetch_output()
load_plugins.assert_not_called()
activate.assert_not_called()


def test_application_execute_plugin_command(with_add_command_plugin: None) -> None:
app = Application()

Expand All @@ -83,13 +101,14 @@ def test_application_execute_plugin_command(with_add_command_plugin: None) -> No
assert tester.status_code == 0


@pytest.mark.parametrize("command", ["foo --no-plugins", "foo -- --no-plugins"])
def test_application_execute_plugin_command_with_plugins_disabled(
with_add_command_plugin: None,
command: str, with_add_command_plugin: None
) -> None:
app = Application()

tester = ApplicationTester(app)
tester.execute("foo --no-plugins")
tester.execute(command)

assert tester.io.fetch_output() == ""
assert "The requested command foo does not exist." in tester.io.fetch_error()
Expand Down
Loading