Skip to content

Commit 14b7f1e

Browse files
authored
Cleo 2.0 (#7070)
1 parent ba97fea commit 14b7f1e

File tree

17 files changed

+180
-79
lines changed

17 files changed

+180
-79
lines changed

poetry.lock

+112-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2-5
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ poetry-core = "^1.3.2"
5151
poetry-plugin-export = "^1.2.0"
5252
"backports.cached-property" = { version = "^1.0.2", python = "<3.8" }
5353
cachecontrol = { version = "^0.12.9", extras = ["filecache"] }
54-
cleo = "^1.0.0a5"
55-
crashtest = "^0.3.0"
54+
cleo = "^2.0.0"
55+
crashtest = "^0.4.1"
5656
dulwich = "^0.20.46"
5757
filelock = "^3.8.0"
5858
html5lib = "^1.0"
@@ -168,9 +168,6 @@ warn_unused_ignores = false
168168
[[tool.mypy.overrides]]
169169
module = [
170170
'cachecontrol.*',
171-
'cachy.*',
172-
'cleo.*',
173-
'crashtest.*',
174171
'lockfile.*',
175172
'pexpect.*',
176173
'pkginfo.*',

src/poetry/console/application.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
from contextlib import suppress
77
from importlib import import_module
88
from typing import TYPE_CHECKING
9-
from typing import Any
109
from typing import cast
1110

1211
from cleo.application import Application as BaseApplication
12+
from cleo.events.console_command_event import ConsoleCommandEvent
1313
from cleo.events.console_events import COMMAND
1414
from cleo.events.event_dispatcher import EventDispatcher
15-
from cleo.exceptions import CleoException
15+
from cleo.exceptions import CleoError
1616
from cleo.formatters.style import Style
1717
from cleo.io.null_io import NullIO
1818

@@ -24,7 +24,7 @@
2424
if TYPE_CHECKING:
2525
from collections.abc import Callable
2626

27-
from cleo.events.console_command_event import ConsoleCommandEvent
27+
from cleo.events.event import Event
2828
from cleo.io.inputs.argv_input import ArgvInput
2929
from cleo.io.inputs.definition import Definition
3030
from cleo.io.inputs.input import Input
@@ -93,7 +93,7 @@ def _load() -> Command:
9393
]
9494

9595

96-
class Application(BaseApplication): # type: ignore[misc]
96+
class Application(BaseApplication):
9797
def __init__(self) -> None:
9898
super().__init__("poetry", __version__)
9999

@@ -137,8 +137,8 @@ def poetry(self) -> Poetry:
137137

138138
@property
139139
def command_loader(self) -> CommandLoader:
140-
command_loader: CommandLoader | None = self._command_loader
141-
assert command_loader is not None
140+
command_loader = self._command_loader
141+
assert isinstance(command_loader, CommandLoader)
142142
return command_loader
143143

144144
def reset_poetry(self) -> None:
@@ -194,7 +194,7 @@ def _configure_io(self, io: IO) -> None:
194194
# We need to check if the command being run
195195
# is the "run" command.
196196
definition = self.definition
197-
with suppress(CleoException):
197+
with suppress(CleoError):
198198
io.input.bind(definition)
199199

200200
name = io.input.first_argument
@@ -215,7 +215,7 @@ def _configure_io(self, io: IO) -> None:
215215
for shortcut in shortcuts:
216216
run_input.add_parameter_option("-" + shortcut.lstrip("-"))
217217

218-
with suppress(CleoException):
218+
with suppress(CleoError):
219219
run_input.bind(definition)
220220

221221
for option_name, value in input.options.items():
@@ -227,12 +227,13 @@ def _configure_io(self, io: IO) -> None:
227227
super()._configure_io(io)
228228

229229
def register_command_loggers(
230-
self, event: ConsoleCommandEvent, event_name: str, _: Any
230+
self, event: Event, event_name: str, _: EventDispatcher
231231
) -> None:
232232
from poetry.console.logging.filters import POETRY_FILTER
233233
from poetry.console.logging.io_formatter import IOFormatter
234234
from poetry.console.logging.io_handler import IOHandler
235235

236+
assert isinstance(event, ConsoleCommandEvent)
236237
command = event.command
237238
if not isinstance(command, Command):
238239
return
@@ -277,12 +278,11 @@ def register_command_loggers(
277278

278279
logger.setLevel(_level)
279280

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

285+
assert isinstance(event, ConsoleCommandEvent)
286286
command = event.command
287287
if not isinstance(command, EnvCommand) or isinstance(command, SelfCommand):
288288
return
@@ -305,10 +305,11 @@ def configure_env(
305305

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

312+
assert isinstance(event, ConsoleCommandEvent)
312313
command = event.command
313314
if not isinstance(command, InstallerCommand):
314315
return

src/poetry/console/command_loader.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import TYPE_CHECKING
44

5-
from cleo.exceptions import LogicException
5+
from cleo.exceptions import CleoLogicError
66
from cleo.loaders.factory_command_loader import FactoryCommandLoader
77

88

@@ -12,11 +12,11 @@
1212
from cleo.commands.command import Command
1313

1414

15-
class CommandLoader(FactoryCommandLoader): # type: ignore[misc]
15+
class CommandLoader(FactoryCommandLoader):
1616
def register_factory(
1717
self, command_name: str, factory: Callable[[], Command]
1818
) -> None:
1919
if command_name in self._factories:
20-
raise LogicException(f'The command "{command_name}" already exists.')
20+
raise CleoLogicError(f'The command "{command_name}" already exists.')
2121

2222
self._factories[command_name] = factory

src/poetry/console/commands/command.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
from typing import Any
55

66
from cleo.commands.command import Command as BaseCommand
7-
from cleo.exceptions import ValueException
7+
from cleo.exceptions import CleoValueError
88

99

1010
if TYPE_CHECKING:
1111
from poetry.console.application import Application
1212
from poetry.poetry import Poetry
1313

1414

15-
class Command(BaseCommand): # type: ignore[misc]
15+
class Command(BaseCommand):
1616
loggers: list[str] = []
1717

1818
_poetry: Poetry | None = None
@@ -28,7 +28,10 @@ def set_poetry(self, poetry: Poetry) -> None:
2828
self._poetry = poetry
2929

3030
def get_application(self) -> Application:
31-
application: Application = self.application
31+
from poetry.console.application import Application
32+
33+
application = self.application
34+
assert isinstance(application, Application)
3235
return application
3336

3437
def reset_poetry(self) -> None:
@@ -37,5 +40,5 @@ def reset_poetry(self) -> None:
3740
def option(self, name: str, default: Any = None) -> Any:
3841
try:
3942
return super().option(name)
40-
except ValueException:
43+
except CleoValueError:
4144
return default

src/poetry/console/commands/debug/info.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def handle(self) -> int:
2222
]
2323
)
2424
)
25-
command = self.application.get("env info")
25+
command = self.get_application().get("env info")
2626

2727
exit_code: int = command.run(self.io)
2828
return exit_code

src/poetry/console/commands/debug/resolve.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from typing import TYPE_CHECKING
4+
35
from cleo.helpers import argument
46
from cleo.helpers import option
57
from cleo.io.outputs.output import Verbosity
@@ -8,6 +10,10 @@
810
from poetry.console.commands.show import ShowCommand
911

1012

13+
if TYPE_CHECKING:
14+
from cleo.ui.table import Rows
15+
16+
1117
class DebugResolveCommand(InitCommand):
1218
name = "debug resolve"
1319
description = "Debugs dependency resolution."
@@ -86,7 +92,7 @@ def handle(self) -> int:
8692
self.line("")
8793

8894
if self.option("tree"):
89-
show_command = self.application.find("show")
95+
show_command = self.get_application().find("show")
9096
assert isinstance(show_command, ShowCommand)
9197
show_command.init_styles(self.io)
9298

@@ -103,7 +109,7 @@ def handle(self) -> int:
103109

104110
table = self.table(style="compact")
105111
table.style.set_vertical_border_chars("", " ")
106-
rows = []
112+
rows: Rows = []
107113

108114
if self.option("install"):
109115
env = EnvManager(self.poetry).get()

src/poetry/console/commands/init.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def handle(self) -> int:
176176
self._determine_requirements(self.option("dependency"))
177177
)
178178

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

192192
help_displayed = False
193-
if self.confirm(question, True):
193+
if self.confirm(question_text, True):
194194
if self.io.is_interactive():
195195
self.line(help_message)
196196
help_displayed = True
@@ -206,10 +206,10 @@ def handle(self) -> int:
206206
self._determine_requirements(self.option("dev-dependency"))
207207
)
208208

209-
question = (
209+
question_text = (
210210
"Would you like to define your development dependencies interactively?"
211211
)
212-
if self.confirm(question, True):
212+
if self.confirm(question_text, True):
213213
if self.io.is_interactive() and not help_displayed:
214214
self.line(help_message)
215215

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

344344
package_constraint = self.ask(question)
345345

src/poetry/console/commands/show.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
if TYPE_CHECKING:
1414
from cleo.io.io import IO
15+
from cleo.ui.table import Rows
1516
from packaging.utils import NormalizedName
1617
from poetry.core.packages.dependency import Dependency
1718
from poetry.core.packages.package import Package
@@ -160,7 +161,7 @@ def _display_single_package_information(
160161

161162
return 0
162163

163-
rows = [
164+
rows: Rows = [
164165
["<info>name</>", f" : <c1>{pkg.pretty_name}</>"],
165166
["<info>version</>", f" : <b>{pkg.pretty_version}</b>"],
166167
["<info>description</>", f" : {pkg.description}"],

src/poetry/console/commands/source/show.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
from __future__ import annotations
22

3+
from typing import TYPE_CHECKING
4+
35
from cleo.helpers import argument
46

57
from poetry.console.commands.command import Command
68

79

10+
if TYPE_CHECKING:
11+
from cleo.ui.table import Rows
12+
13+
814
class SourceShowCommand(Command):
915
name = "source show"
1016
description = "Show information about sources configured for the project."
@@ -40,7 +46,7 @@ def handle(self) -> int:
4046
continue
4147

4248
table = self.table(style="compact")
43-
rows = [
49+
rows: Rows = [
4450
["<info>name</>", f" : <c1>{source.name}</>"],
4551
["<info>url</>", f" : {source.url}"],
4652
[

src/poetry/console/exceptions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

3-
from cleo.exceptions import CleoSimpleException
3+
from cleo.exceptions import CleoError
44

55

6-
class PoetrySimpleConsoleException(CleoSimpleException): # type: ignore[misc]
6+
class PoetryConsoleError(CleoError):
77
pass

src/poetry/console/io/inputs/run_argv_input.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from cleo.io.inputs.definition import Definition
1010

1111

12-
class RunArgvInput(ArgvInput): # type: ignore[misc]
12+
class RunArgvInput(ArgvInput):
1313
def __init__(
1414
self,
1515
argv: list[str] | None = None,

src/poetry/mixology/solutions/providers/python_requirement_solution_provider.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66

77
from crashtest.contracts.has_solutions_for_exception import HasSolutionsForException
88

9+
from poetry.puzzle.exceptions import SolverProblemError
10+
911

1012
if TYPE_CHECKING:
1113
from crashtest.contracts.solution import Solution
1214

13-
from poetry.puzzle.exceptions import SolverProblemError
14-
1515

16-
class PythonRequirementSolutionProvider(HasSolutionsForException): # type: ignore[misc]
16+
class PythonRequirementSolutionProvider(HasSolutionsForException):
1717
def can_solve(self, exception: Exception) -> bool:
18-
from poetry.puzzle.exceptions import SolverProblemError
19-
2018
if not isinstance(exception, SolverProblemError):
2119
return False
2220

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

2927
return bool(m)
3028

31-
def get_solutions(self, exception: SolverProblemError) -> list[Solution]:
29+
def get_solutions(self, exception: Exception) -> list[Solution]:
3230
from poetry.mixology.solutions.solutions.python_requirement_solution import (
3331
PythonRequirementSolution,
3432
)
3533

34+
assert isinstance(exception, SolverProblemError)
3635
return [PythonRequirementSolution(exception)]

src/poetry/mixology/solutions/solutions/python_requirement_solution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from poetry.puzzle.exceptions import SolverProblemError
1111

1212

13-
class PythonRequirementSolution(Solution): # type: ignore[misc]
13+
class PythonRequirementSolution(Solution):
1414
def __init__(self, exception: SolverProblemError) -> None:
1515
from poetry.core.constraints.version import parse_constraint
1616

src/poetry/puzzle/provider.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
logger = logging.getLogger(__name__)
6060

6161

62-
class Indicator(ProgressIndicator): # type: ignore[misc]
62+
class Indicator(ProgressIndicator):
6363
CONTEXT: str | None = None
6464

6565
@staticmethod

0 commit comments

Comments
 (0)