1
1
from __future__ import annotations
2
2
3
- from collections import defaultdict
3
+ import dataclasses
4
+
4
5
from typing import TYPE_CHECKING
5
- from typing import DefaultDict
6
6
7
7
from poetry .console .commands .self .self_command import SelfCommand
8
8
9
9
10
10
if TYPE_CHECKING :
11
+ from entrypoints import EntryPoint
11
12
from poetry .core .packages .package import Package
12
13
13
14
15
+ @dataclasses .dataclass
16
+ class PluginPackage :
17
+ package : Package
18
+ plugins : list [EntryPoint ] = dataclasses .field (default_factory = list )
19
+ application_plugins : list [EntryPoint ] = dataclasses .field (default_factory = list )
20
+
21
+
14
22
class SelfShowPluginsCommand (SelfCommand ):
15
23
name = "self show plugins"
16
24
description = "Shows information about the currently installed plugins."
@@ -32,13 +40,7 @@ def _system_project_handle(self) -> int:
32
40
from poetry .utils .helpers import canonicalize_name
33
41
from poetry .utils .helpers import pluralize
34
42
35
- plugins : DefaultDict [str , dict [str , Package | list [str ]]] = defaultdict (
36
- lambda : {
37
- "package" : None ,
38
- "plugins" : [],
39
- "application_plugins" : [],
40
- }
41
- )
43
+ plugins : dict [str , PluginPackage ] = {}
42
44
43
45
system_env = EnvManager .get_system_env (naive = True )
44
46
entry_points = PluginManager (ApplicationPlugin .group ).get_plugin_entry_points (
@@ -48,33 +50,41 @@ def _system_project_handle(self) -> int:
48
50
system_env , with_dependencies = True
49
51
)
50
52
51
- packages_by_name = {pkg .name : pkg for pkg in installed_repository .packages }
53
+ packages_by_name : dict [str , Package ] = {
54
+ pkg .name : pkg for pkg in installed_repository .packages
55
+ }
52
56
53
57
for entry_point in entry_points :
54
58
plugin = entry_point .load ()
55
- category = "plugins"
56
- if issubclass (plugin , ApplicationPlugin ):
57
- category = "application_plugins"
58
59
59
60
package = packages_by_name [canonicalize_name (entry_point .distro .name )]
60
- plugins [package .pretty_name ]["package" ] = package
61
- plugins [package .pretty_name ][category ].append (entry_point )
61
+
62
+ name = package .pretty_name
63
+ info = plugins .get (name ) or PluginPackage (package = package )
64
+
65
+ if issubclass (plugin , ApplicationPlugin ):
66
+ info .application_plugins .append (entry_point )
67
+ else :
68
+ info .plugins .append (entry_point )
69
+
70
+ plugins [name ] = info
62
71
63
72
for name , info in plugins .items ():
64
- package = info [ " package" ]
73
+ package = info . package
65
74
description = " " + package .description if package .description else ""
66
75
self .line ("" )
67
76
self .line (f" • <c1>{ name } </c1> (<c2>{ package .version } </c2>){ description } " )
68
77
provide_line = " "
69
- if info ["plugins" ]:
70
- count = len (info ["plugins" ])
78
+
79
+ if info .plugins :
80
+ count = len (info .plugins )
71
81
provide_line += f" <info>{ count } </info> plugin{ pluralize (count )} "
72
82
73
- if info [ " application_plugins" ] :
74
- if info [ " plugins" ] :
83
+ if info . application_plugins :
84
+ if info . plugins :
75
85
provide_line += " and"
76
86
77
- count = len (info [ " application_plugins" ] )
87
+ count = len (info . application_plugins )
78
88
provide_line += (
79
89
f" <info>{ count } </info> application plugin{ pluralize (count )} "
80
90
)
0 commit comments