-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathplugin.py
More file actions
49 lines (36 loc) · 1.67 KB
/
plugin.py
File metadata and controls
49 lines (36 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from __future__ import annotations
from typing import TYPE_CHECKING
from typing import Any
from typing import cast
from cleo.events.console_events import COMMAND
from poetry.plugins.application_plugin import ApplicationPlugin
from poetry_plugin_bundle.console.commands.bundle.archive import BundleArchiveCommand
from poetry_plugin_bundle.console.commands.bundle.venv import BundleVenvCommand
if TYPE_CHECKING:
from cleo.events.console_command_event import ConsoleCommandEvent
from poetry.console.application import Application
from poetry.console.commands.command import Command
class BundleApplicationPlugin(ApplicationPlugin):
@property
def commands(self) -> list[type[Command]]:
return [BundleVenvCommand, BundleArchiveCommand]
def activate(self, application: Application) -> None:
assert application.event_dispatcher
application.event_dispatcher.add_listener(
COMMAND, self.configure_bundle_commands # type: ignore[arg-type]
)
super().activate(application=application)
def configure_bundle_commands(
self, event: ConsoleCommandEvent, event_name: str, _: Any
) -> None:
from poetry_plugin_bundle.console.commands.bundle.bundle_command import (
BundleCommand,
)
command: BundleCommand = cast(BundleCommand, event.command)
if not isinstance(command, BundleCommand):
return
# If the command already has a bundler manager, do nothing
if command.bundler_manager is not None:
return
from poetry_plugin_bundle.bundlers.bundler_manager import BundlerManager
command.set_bundler_manager(BundlerManager())