Commit cb1c9fa0 by Arun Babu Neelicattu

typing: fix mypy inspection issues

parent 7ab4cf3a
...@@ -27,10 +27,12 @@ class PluginShowCommand(Command): ...@@ -27,10 +27,12 @@ class PluginShowCommand(Command):
command: SelfShowPluginsCommand = cast( command: SelfShowPluginsCommand = cast(
SelfShowPluginsCommand, application.find("self show plugins") SelfShowPluginsCommand, application.find("self show plugins")
) )
return command.run(
exit_code: int = command.run(
IO( IO(
StringInput(""), StringInput(""),
self._io.output, self._io.output,
self._io.error_output, self._io.error_output,
) )
) )
return exit_code
...@@ -45,7 +45,7 @@ class SelfCommand(InstallerCommand): ...@@ -45,7 +45,7 @@ class SelfCommand(InstallerCommand):
@property @property
def env(self) -> Env: def env(self) -> Env:
if self._env is None or not isinstance(self._env, SystemEnv): if not isinstance(self._env, SystemEnv):
self.reset_env() self.reset_env()
return self._env return self._env
...@@ -102,7 +102,7 @@ class SelfCommand(InstallerCommand): ...@@ -102,7 +102,7 @@ class SelfCommand(InstallerCommand):
The default implementations handles cases where a `self` command delegates The default implementations handles cases where a `self` command delegates
handling to an existing command. Eg: `SelfAddCommand(SelfCommand, AddCommand)`. handling to an existing command. Eg: `SelfAddCommand(SelfCommand, AddCommand)`.
""" """
return super().handle() return cast(int, super().handle())
def reset(self) -> None: def reset(self) -> None:
""" """
......
...@@ -30,4 +30,5 @@ file. ...@@ -30,4 +30,5 @@ file.
if self.option("addons", False): if self.option("addons", False):
return {SelfCommand.ADDITIONAL_PACKAGE_GROUP} return {SelfCommand.ADDITIONAL_PACKAGE_GROUP}
return super(ShowCommand, self).activated_groups groups: set[str] = super(ShowCommand, self).activated_groups
return groups
from __future__ import annotations from __future__ import annotations
from collections import defaultdict import dataclasses
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from typing import DefaultDict
from poetry.console.commands.self.self_command import SelfCommand from poetry.console.commands.self.self_command import SelfCommand
if TYPE_CHECKING: if TYPE_CHECKING:
from entrypoints import EntryPoint
from poetry.core.packages.package import Package from poetry.core.packages.package import Package
@dataclasses.dataclass
class PluginPackage:
package: Package
plugins: list[EntryPoint] = dataclasses.field(default_factory=list)
application_plugins: list[EntryPoint] = dataclasses.field(default_factory=list)
class SelfShowPluginsCommand(SelfCommand): class SelfShowPluginsCommand(SelfCommand):
name = "self show plugins" name = "self show plugins"
description = "Shows information about the currently installed plugins." description = "Shows information about the currently installed plugins."
...@@ -32,13 +40,7 @@ commands respectively. ...@@ -32,13 +40,7 @@ commands respectively.
from poetry.utils.helpers import canonicalize_name from poetry.utils.helpers import canonicalize_name
from poetry.utils.helpers import pluralize from poetry.utils.helpers import pluralize
plugins: DefaultDict[str, dict[str, Package | list[str]]] = defaultdict( plugins: dict[str, PluginPackage] = {}
lambda: {
"package": None,
"plugins": [],
"application_plugins": [],
}
)
system_env = EnvManager.get_system_env(naive=True) system_env = EnvManager.get_system_env(naive=True)
entry_points = PluginManager(ApplicationPlugin.group).get_plugin_entry_points( entry_points = PluginManager(ApplicationPlugin.group).get_plugin_entry_points(
...@@ -48,33 +50,42 @@ commands respectively. ...@@ -48,33 +50,42 @@ commands respectively.
system_env, with_dependencies=True system_env, with_dependencies=True
) )
packages_by_name = {pkg.name: pkg for pkg in installed_repository.packages} packages_by_name: dict[str, Package] = {
pkg.name: pkg for pkg in installed_repository.packages
}
for entry_point in entry_points: for entry_point in entry_points:
plugin = entry_point.load() plugin = entry_point.load()
category = "plugins"
if issubclass(plugin, ApplicationPlugin):
category = "application_plugins"
assert entry_point.distro is not None
package = packages_by_name[canonicalize_name(entry_point.distro.name)] package = packages_by_name[canonicalize_name(entry_point.distro.name)]
plugins[package.pretty_name]["package"] = package
plugins[package.pretty_name][category].append(entry_point) name = package.pretty_name
info = plugins.get(name) or PluginPackage(package=package)
if issubclass(plugin, ApplicationPlugin):
info.application_plugins.append(entry_point)
else:
info.plugins.append(entry_point)
plugins[name] = info
for name, info in plugins.items(): for name, info in plugins.items():
package = info["package"] package = info.package
description = " " + package.description if package.description else "" description = " " + package.description if package.description else ""
self.line("") self.line("")
self.line(f" • <c1>{name}</c1> (<c2>{package.version}</c2>){description}") self.line(f" • <c1>{name}</c1> (<c2>{package.version}</c2>){description}")
provide_line = " " provide_line = " "
if info["plugins"]:
count = len(info["plugins"]) if info.plugins:
count = len(info.plugins)
provide_line += f" <info>{count}</info> plugin{pluralize(count)}" provide_line += f" <info>{count}</info> plugin{pluralize(count)}"
if info["application_plugins"]: if info.application_plugins:
if info["plugins"]: if info.plugins:
provide_line += " and" provide_line += " and"
count = len(info["application_plugins"]) count = len(info.application_plugins)
provide_line += ( provide_line += (
f" <info>{count}</info> application plugin{pluralize(count)}" f" <info>{count}</info> application plugin{pluralize(count)}"
) )
......
...@@ -50,10 +50,11 @@ environment. ...@@ -50,10 +50,11 @@ environment.
if self.option("preview"): if self.option("preview"):
argv.append("--allow-prereleases") argv.append("--allow-prereleases")
return add_command.run( exit_code: int = add_command.run(
IO( IO(
StringInput(" ".join(argv)), StringInput(" ".join(argv)),
self._io.output, self._io.output,
self._io.error_output, self._io.error_output,
) )
) )
return exit_code
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