Skip to content
Closed
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
19 changes: 10 additions & 9 deletions src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from contextlib import suppress
from importlib import import_module
from typing import TYPE_CHECKING
from typing import Any
from typing import cast

from cleo.application import Application as BaseApplication
from cleo.events.console_command_event import ConsoleCommandEvent
from cleo.events.console_events import COMMAND
from cleo.events.event_dispatcher import EventDispatcher
from cleo.exceptions import CleoException
Expand All @@ -24,7 +24,7 @@
if TYPE_CHECKING:
from collections.abc import Callable

from cleo.events.console_command_event import ConsoleCommandEvent
from cleo.events.event import Event
from cleo.io.inputs.argv_input import ArgvInput
from cleo.io.inputs.definition import Definition
from cleo.io.inputs.input import Input
Expand Down Expand Up @@ -137,8 +137,8 @@ def poetry(self) -> Poetry:

@property
def command_loader(self) -> CommandLoader:
command_loader: CommandLoader | None = self._command_loader
assert command_loader is not None
command_loader = self._command_loader
assert isinstance(command_loader, CommandLoader)
return command_loader

def reset_poetry(self) -> None:
Expand Down Expand Up @@ -227,12 +227,13 @@ def _configure_io(self, io: IO) -> None:
super()._configure_io(io)

def register_command_loggers(
self, event: ConsoleCommandEvent, event_name: str, _: Any
self, event: Event, event_name: str, _: EventDispatcher
) -> None:
from poetry.console.logging.filters import POETRY_FILTER
from poetry.console.logging.io_formatter import IOFormatter
from poetry.console.logging.io_handler import IOHandler

assert isinstance(event, ConsoleCommandEvent)
command = event.command
if not isinstance(command, Command):
return
Expand Down Expand Up @@ -277,12 +278,11 @@ def register_command_loggers(

logger.setLevel(_level)

def configure_env(
self, event: ConsoleCommandEvent, event_name: str, _: Any
) -> None:
def configure_env(self, event: Event, event_name: str, _: EventDispatcher) -> None:
from poetry.console.commands.env_command import EnvCommand
from poetry.console.commands.self.self_command import SelfCommand

assert isinstance(event, ConsoleCommandEvent)
command = event.command
if not isinstance(command, EnvCommand) or isinstance(command, SelfCommand):
return
Expand All @@ -305,10 +305,11 @@ def configure_env(

@classmethod
def configure_installer_for_event(
cls, event: ConsoleCommandEvent, event_name: str, _: Any
cls, event: Event, event_name: str, _: EventDispatcher
) -> None:
from poetry.console.commands.installer_command import InstallerCommand

assert isinstance(event, ConsoleCommandEvent)
command = event.command
if not isinstance(command, InstallerCommand):
return
Expand Down
5 changes: 4 additions & 1 deletion src/poetry/console/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def set_poetry(self, poetry: Poetry) -> None:
self._poetry = poetry

def get_application(self) -> Application:
application: Application = self.application
from poetry.console.application import Application

application = self.application
assert isinstance(application, Application)
return application

def reset_poetry(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/debug/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def handle(self) -> int:
]
)
)
command = self.application.get("env info")
command = self.get_application().get("env info")

exit_code: int = command.run(self.io)
return exit_code
2 changes: 1 addition & 1 deletion src/poetry/console/commands/debug/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def handle(self) -> int:
self.line("")

if self.option("tree"):
show_command = self.application.find("show")
show_command = self.get_application().find("show")
assert isinstance(show_command, ShowCommand)
show_command.init_styles(self.io)

Expand Down
12 changes: 6 additions & 6 deletions src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def handle(self) -> int:
self._determine_requirements(self.option("dependency"))
)

question = "Would you like to define your main dependencies interactively?"
question_text = "Would you like to define your main dependencies interactively?"
help_message = """\
You can specify a package in the following forms:
- A single name (<b>requests</b>): this will search for matches on PyPI
Expand All @@ -190,7 +190,7 @@ def handle(self) -> int:
"""

help_displayed = False
if self.confirm(question, True):
if self.confirm(question_text, True):
if self.io.is_interactive():
self.line(help_message)
help_displayed = True
Expand All @@ -206,10 +206,10 @@ def handle(self) -> int:
self._determine_requirements(self.option("dev-dependency"))
)

question = (
question_text = (
"Would you like to define your development dependencies interactively?"
)
if self.confirm(question, True):
if self.confirm(question_text, True):
if self.io.is_interactive() and not help_displayed:
self.line(help_message)

Expand Down Expand Up @@ -338,8 +338,8 @@ def _determine_requirements(
"Enter the version constraint to require "
"(or leave blank to use the latest version):"
)
question.attempts = 3
question.validator = lambda x: (x or "").strip() or False
question.set_max_attempts(3)
question.set_validator(lambda x: (x or "").strip() or None)

package_constraint = self.ask(question)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@

from crashtest.contracts.has_solutions_for_exception import HasSolutionsForException

from poetry.puzzle.exceptions import SolverProblemError


if TYPE_CHECKING:
from crashtest.contracts.solution import Solution

from poetry.puzzle.exceptions import SolverProblemError


class PythonRequirementSolutionProvider(HasSolutionsForException): # type: ignore[misc]
def can_solve(self, exception: Exception) -> bool:
from poetry.puzzle.exceptions import SolverProblemError

if not isinstance(exception, SolverProblemError):
return False

Expand All @@ -28,9 +26,10 @@ def can_solve(self, exception: Exception) -> bool:

return bool(m)

def get_solutions(self, exception: SolverProblemError) -> list[Solution]:
def get_solutions(self, exception: Exception) -> list[Solution]:
from poetry.mixology.solutions.solutions.python_requirement_solution import (
PythonRequirementSolution,
)

assert isinstance(exception, SolverProblemError)
return [PythonRequirementSolution(exception)]