Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): sort global opts prior to io config #10128

Merged
merged 1 commit into from
Jan 30, 2025
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
10 changes: 8 additions & 2 deletions src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ def _configure_global_options(self, io: IO) -> None:
:param io: The IO instance whose input and options are being read.
:return: Nothing.
"""
self._sort_global_options(io)

self._disable_plugins = io.input.option("no-plugins")
self._disable_cache = io.input.option("no-cache")

Expand Down Expand Up @@ -351,8 +349,15 @@ def _sort_global_options(self, io: IO) -> None:
tokens.append(str(value))

sorted_input = ArgvInput([self._name or "", *tokens, *remaining_args])

# this is required to ensure stdin is transferred
sorted_input.set_stream(original_input.stream)

# this is required as cleo internally checks for `io.input._interactive`
# when configuring io, and cleo's test applications overrides this attribute
# explicitly causing test setups to fail
sorted_input.interactive(io.input.is_interactive())

with suppress(CleoError):
sorted_input.bind(self.definition)

Expand Down Expand Up @@ -450,6 +455,7 @@ def _configure_run_command(self, io: IO) -> None:

def _configure_io(self, io: IO) -> None:
self._configure_run_command(io)
self._sort_global_options(io)
super()._configure_io(io)

def register_command_loggers(
Expand Down
27 changes: 27 additions & 0 deletions tests/console/test_application_global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import pytest

from cleo.io.buffered_io import BufferedIO
from cleo.io.inputs.string_input import StringInput
from cleo.testers.application_tester import ApplicationTester

from poetry.console.application import Application
Expand Down Expand Up @@ -177,3 +179,28 @@ def test_application_with_relative_project_parameter(
ProjectPath: {project_source_directory}
WorkingDirectory: {cwd}
""")


@pytest.mark.parametrize(
("parameter", "check", "result"),
[
("--ansi", "is_decorated", True),
("--no-ansi", "is_decorated", False),
("--no-interaction", "is_interactive", False),
("--verbose", "is_verbose", True),
("-vv", "is_verbose", True),
("-vv", "is_very_verbose", True),
("-vv", "is_debug", False),
("-vvv", "is_debug", True),
],
)
def test_application_io_options_are_set(
parameter: str, check: str, result: bool
) -> None:
# we use an actual application here to avoid cleo's testing overrides
application = Application()
application.auto_exits(False)
application._io = BufferedIO()

assert application.run(StringInput(f"{parameter} about")) == 0
assert getattr(application._io, check)() == result