Commit e0bc7f3f by David Hotham Committed by Bjorn Neergaard

more typechecking

parent ec610a34
...@@ -38,13 +38,13 @@ if TYPE_CHECKING: ...@@ -38,13 +38,13 @@ if TYPE_CHECKING:
from poetry.poetry import Poetry from poetry.poetry import Poetry
def load_command(name: str) -> Callable[[], type[Command]]: def load_command(name: str) -> Callable[[], Command]:
def _load() -> type[Command]: def _load() -> Command:
words = name.split(" ") words = name.split(" ")
module = import_module("poetry.console.commands." + ".".join(words)) module = import_module("poetry.console.commands." + ".".join(words))
command_class = getattr(module, "".join(c.title() for c in words) + "Command") command_class = getattr(module, "".join(c.title() for c in words) + "Command")
command_type: type[Command] = command_class() command: Command = command_class()
return command_type return command
return _load return _load
...@@ -136,7 +136,8 @@ class Application(BaseApplication): # type: ignore[misc] ...@@ -136,7 +136,8 @@ class Application(BaseApplication): # type: ignore[misc]
@property @property
def command_loader(self) -> CommandLoader: def command_loader(self) -> CommandLoader:
command_loader: CommandLoader = self._command_loader command_loader: CommandLoader | None = self._command_loader
assert command_loader is not None
return command_loader return command_loader
def reset_poetry(self) -> None: def reset_poetry(self) -> None:
...@@ -333,7 +334,7 @@ class Application(BaseApplication): # type: ignore[misc] ...@@ -333,7 +334,7 @@ class Application(BaseApplication): # type: ignore[misc]
installer.use_executor(poetry.config.get("experimental.new-installer", False)) installer.use_executor(poetry.config.get("experimental.new-installer", False))
command.set_installer(installer) command.set_installer(installer)
def _load_plugins(self, io: IO = None) -> None: def _load_plugins(self, io: IO | None = None) -> None:
if self._plugins_loaded: if self._plugins_loaded:
return return
......
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING
from cleo.helpers import argument from cleo.helpers import argument
from cleo.helpers import option from cleo.helpers import option
from cleo.io.outputs.output import Verbosity from cleo.io.outputs.output import Verbosity
from poetry.console.commands.init import InitCommand from poetry.console.commands.init import InitCommand
from poetry.console.commands.show import ShowCommand
if TYPE_CHECKING:
from poetry.console.commands.show import ShowCommand
class DebugResolveCommand(InitCommand): class DebugResolveCommand(InitCommand):
...@@ -94,7 +89,8 @@ class DebugResolveCommand(InitCommand): ...@@ -94,7 +89,8 @@ class DebugResolveCommand(InitCommand):
self.line("") self.line("")
if self.option("tree"): if self.option("tree"):
show_command: ShowCommand = self.application.find("show") show_command = self.application.find("show")
assert isinstance(show_command, ShowCommand)
show_command.init_styles(self.io) show_command.init_styles(self.io)
packages = [op.package for op in ops] packages = [op.package for op in ops]
......
...@@ -45,7 +45,8 @@ It works similarly to the <c1>add</c1> command: ...@@ -45,7 +45,8 @@ It works similarly to the <c1>add</c1> command:
self.line_error(self.deprecation) self.line_error(self.deprecation)
application = self.get_application() application = self.get_application()
command: SelfAddCommand = application.find("self add") command = application.find("self add")
assert isinstance(command, SelfAddCommand)
application.configure_installer_for_command(command, self.io) application.configure_installer_for_command(command, self.io)
argv: list[str] = ["add", *self.argument("plugins")] argv: list[str] = ["add", *self.argument("plugins")]
......
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING
from cleo.helpers import argument from cleo.helpers import argument
from cleo.helpers import option from cleo.helpers import option
from cleo.io.inputs.string_input import StringInput from cleo.io.inputs.string_input import StringInput
from cleo.io.io import IO from cleo.io.io import IO
from poetry.console.commands.command import Command from poetry.console.commands.command import Command
from poetry.console.commands.self.remove import SelfRemoveCommand
if TYPE_CHECKING:
from poetry.console.commands.self.remove import SelfRemoveCommand
class PluginRemoveCommand(Command): class PluginRemoveCommand(Command):
...@@ -43,7 +38,8 @@ class PluginRemoveCommand(Command): ...@@ -43,7 +38,8 @@ class PluginRemoveCommand(Command):
self.line_error(self.help) self.line_error(self.help)
application = self.get_application() application = self.get_application()
command: SelfRemoveCommand = application.find("self remove") command = application.find("self remove")
assert isinstance(command, SelfRemoveCommand)
application.configure_installer_for_command(command, self.io) application.configure_installer_for_command(command, self.io)
argv: list[str] = ["remove", *self.argument("plugins")] argv: list[str] = ["remove", *self.argument("plugins")]
......
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING
from cleo.io.inputs.string_input import StringInput from cleo.io.inputs.string_input import StringInput
from cleo.io.io import IO from cleo.io.io import IO
from poetry.console.commands.command import Command from poetry.console.commands.command import Command
if TYPE_CHECKING:
from poetry.console.commands.self.show.plugins import SelfShowPluginsCommand
class PluginShowCommand(Command): class PluginShowCommand(Command):
name = "plugin show" name = "plugin show"
...@@ -26,7 +20,7 @@ class PluginShowCommand(Command): ...@@ -26,7 +20,7 @@ class PluginShowCommand(Command):
self.line_error(self.help) self.line_error(self.help)
application = self.get_application() application = self.get_application()
command: SelfShowPluginsCommand = application.find("self show plugins") command = application.find("self show plugins")
exit_code: int = command.run( exit_code: int = command.run(
IO( IO(
......
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING
from cleo.helpers import argument from cleo.helpers import argument
from cleo.helpers import option from cleo.helpers import option
from cleo.io.inputs.string_input import StringInput from cleo.io.inputs.string_input import StringInput
from cleo.io.io import IO from cleo.io.io import IO
from poetry.console.commands.add import AddCommand
from poetry.console.commands.self.self_command import SelfCommand from poetry.console.commands.self.self_command import SelfCommand
if TYPE_CHECKING:
from poetry.console.commands.add import AddCommand
class SelfUpdateCommand(SelfCommand): class SelfUpdateCommand(SelfCommand):
name = "self update" name = "self update"
description = "Updates Poetry to the latest version." description = "Updates Poetry to the latest version."
...@@ -40,7 +35,8 @@ environment. ...@@ -40,7 +35,8 @@ environment.
def _system_project_handle(self) -> int: def _system_project_handle(self) -> int:
self.write("<info>Updating Poetry version ...</info>\n\n") self.write("<info>Updating Poetry version ...</info>\n\n")
application = self.get_application() application = self.get_application()
add_command: AddCommand = application.find("add") add_command = application.find("add")
assert isinstance(add_command, AddCommand)
add_command.set_env(self.env) add_command.set_env(self.env)
application.configure_installer_for_command(add_command, self.io) application.configure_installer_for_command(add_command, self.io)
......
...@@ -45,6 +45,7 @@ class Factory(BaseFactory): ...@@ -45,6 +45,7 @@ class Factory(BaseFactory):
def create_poetry( def create_poetry(
self, self,
cwd: Path | None = None, cwd: Path | None = None,
with_groups: bool = True,
io: IO | None = None, io: IO | None = None,
disable_plugins: bool = False, disable_plugins: bool = False,
disable_cache: bool = False, disable_cache: bool = False,
...@@ -52,7 +53,7 @@ class Factory(BaseFactory): ...@@ -52,7 +53,7 @@ class Factory(BaseFactory):
if io is None: if io is None:
io = NullIO() io = NullIO()
base_poetry = super().create_poetry(cwd) base_poetry = super().create_poetry(cwd=cwd, with_groups=with_groups)
locker = Locker( locker = Locker(
base_poetry.file.parent / "poetry.lock", base_poetry.local_config base_poetry.file.parent / "poetry.lock", base_poetry.local_config
......
...@@ -258,6 +258,7 @@ class Executor: ...@@ -258,6 +258,7 @@ class Executor:
try: try:
from cleo.ui.exception_trace import ExceptionTrace from cleo.ui.exception_trace import ExceptionTrace
io: IO | SectionOutput
if not self.supports_fancy_output(): if not self.supports_fancy_output():
io = self._io io = self._io
else: else:
......
...@@ -23,4 +23,5 @@ class ApplicationPlugin(BasePlugin): ...@@ -23,4 +23,5 @@ class ApplicationPlugin(BasePlugin):
def activate(self, application: Application) -> None: def activate(self, application: Application) -> None:
for command in self.commands: for command in self.commands:
assert command.name is not None
application.command_loader.register_factory(command.name, lambda: command()) application.command_loader.register_factory(command.name, lambda: command())
...@@ -11,8 +11,7 @@ from poetry.utils.authenticator import Authenticator ...@@ -11,8 +11,7 @@ from poetry.utils.authenticator import Authenticator
if TYPE_CHECKING: if TYPE_CHECKING:
from pathlib import Path from pathlib import Path
from cleo.io import BufferedIO from cleo.io.io import IO
from cleo.io import ConsoleIO
from poetry.poetry import Poetry from poetry.poetry import Poetry
...@@ -24,7 +23,7 @@ class Publisher: ...@@ -24,7 +23,7 @@ class Publisher:
Registers and publishes packages to remote repositories. Registers and publishes packages to remote repositories.
""" """
def __init__(self, poetry: Poetry, io: BufferedIO | ConsoleIO) -> None: def __init__(self, poetry: Poetry, io: IO) -> None:
self._poetry = poetry self._poetry = poetry
self._package = poetry.package self._package = poetry.package
self._io = io self._io = io
......
...@@ -27,7 +27,7 @@ from poetry.utils.patterns import wheel_file_re ...@@ -27,7 +27,7 @@ from poetry.utils.patterns import wheel_file_re
if TYPE_CHECKING: if TYPE_CHECKING:
from cleo.io.null_io import NullIO from cleo.io.io import IO
from poetry.poetry import Poetry from poetry.poetry import Poetry
...@@ -52,7 +52,7 @@ class UploadError(Exception): ...@@ -52,7 +52,7 @@ class UploadError(Exception):
class Uploader: class Uploader:
def __init__(self, poetry: Poetry, io: NullIO) -> None: def __init__(self, poetry: Poetry, io: IO) -> None:
self._poetry = poetry self._poetry = poetry
self._package = poetry.package self._package = poetry.package
self._io = io self._io = io
......
...@@ -79,6 +79,7 @@ class Indicator(ProgressIndicator): # type: ignore[misc] ...@@ -79,6 +79,7 @@ class Indicator(ProgressIndicator): # type: ignore[misc]
return f" <c1>{Indicator.CONTEXT}</> " return f" <c1>{Indicator.CONTEXT}</> "
def _formatter_elapsed(self) -> str: def _formatter_elapsed(self) -> str:
assert self._start_time is not None
elapsed = time.time() - self._start_time elapsed = time.time() - self._start_time
return f"{elapsed:.1f}s" return f"{elapsed:.1f}s"
......
...@@ -1909,7 +1909,10 @@ def build_environment( ...@@ -1909,7 +1909,10 @@ def build_environment(
""" """
if not env or poetry.package.build_script: if not env or poetry.package.build_script:
with ephemeral_environment(executable=env.python if env else None) as venv: with ephemeral_environment(executable=env.python if env else None) as venv:
overwrite = io and io.output.is_decorated() and not io.is_debug() overwrite = (
io is not None and io.output.is_decorated() and not io.is_debug()
)
if io: if io:
if not overwrite: if not overwrite:
io.write_line("") io.write_line("")
...@@ -1923,6 +1926,7 @@ def build_environment( ...@@ -1923,6 +1926,7 @@ def build_environment(
"<b>Preparing</b> build environment with build-system requirements" "<b>Preparing</b> build environment with build-system requirements"
f" {', '.join(requires)}" f" {', '.join(requires)}"
) )
venv.run_pip( venv.run_pip(
"install", "install",
"--disable-pip-version-check", "--disable-pip-version-check",
...@@ -1931,6 +1935,7 @@ def build_environment( ...@@ -1931,6 +1935,7 @@ def build_environment(
) )
if overwrite: if overwrite:
assert io is not None
io.write_line("") io.write_line("")
yield venv yield venv
......
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