Skip to content

Commit d32d667

Browse files
committed
refactor: remove unused parameters from plugin manager (python-poetry#9547)
1 parent 5bab98c commit d32d667

File tree

3 files changed

+14
-35
lines changed

3 files changed

+14
-35
lines changed

src/poetry/factory.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ def create_poetry(
9999
)
100100
)
101101

102-
plugin_manager = PluginManager(Plugin.group, disable_plugins=disable_plugins)
103-
plugin_manager.load_plugins()
104-
plugin_manager.activate(poetry, io)
102+
if not disable_plugins:
103+
plugin_manager = PluginManager(Plugin.group)
104+
plugin_manager.load_plugins()
105+
plugin_manager.activate(poetry, io)
105106

106107
return poetry
107108

src/poetry/plugins/plugin_manager.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
from poetry.plugins.application_plugin import ApplicationPlugin
88
from poetry.plugins.plugin import Plugin
99
from poetry.utils._compat import metadata
10+
from poetry.utils.env import Env
1011

1112

1213
if TYPE_CHECKING:
1314
from typing import Any
1415

15-
from poetry.utils.env import Env
16-
1716

1817
logger = logging.getLogger(__name__)
1918

@@ -23,16 +22,12 @@ class PluginManager:
2322
This class registers and activates plugins.
2423
"""
2524

26-
def __init__(self, group: str, disable_plugins: bool = False) -> None:
25+
def __init__(self, group: str) -> None:
2726
self._group = group
28-
self._disable_plugins = disable_plugins
2927
self._plugins: list[Plugin] = []
3028

31-
def load_plugins(self, env: Env | None = None) -> None:
32-
if self._disable_plugins:
33-
return
34-
35-
plugin_entrypoints = self.get_plugin_entry_points(env=env)
29+
def load_plugins(self) -> None:
30+
plugin_entrypoints = self.get_plugin_entry_points()
3631

3732
for ep in plugin_entrypoints:
3833
self._load_plugin_entry_point(ep)
@@ -58,18 +53,18 @@ def get_plugin_entry_points(
5853
if self._is_plugin_candidate(ep, env)
5954
]
6055

61-
def add_plugin(self, plugin: Plugin) -> None:
56+
def activate(self, *args: Any, **kwargs: Any) -> None:
57+
for plugin in self._plugins:
58+
plugin.activate(*args, **kwargs)
59+
60+
def _add_plugin(self, plugin: Plugin) -> None:
6261
if not isinstance(plugin, (Plugin, ApplicationPlugin)):
6362
raise ValueError(
6463
"The Poetry plugin must be an instance of Plugin or ApplicationPlugin"
6564
)
6665

6766
self._plugins.append(plugin)
6867

69-
def activate(self, *args: Any, **kwargs: Any) -> None:
70-
for plugin in self._plugins:
71-
plugin.activate(*args, **kwargs)
72-
7368
def _load_plugin_entry_point(self, ep: metadata.EntryPoint) -> None:
7469
logger.debug("Loading the %s plugin", ep.name)
7570

@@ -80,4 +75,4 @@ def _load_plugin_entry_point(self, ep: metadata.EntryPoint) -> None:
8075
"The Poetry plugin must be an instance of Plugin or ApplicationPlugin"
8176
)
8277

83-
self.add_plugin(plugin())
78+
self._add_plugin(plugin())

tests/plugins/test_plugin_manager.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ def _manager(group: str = Plugin.group) -> PluginManager:
7575
return _manager
7676

7777

78-
@pytest.fixture()
79-
def no_plugin_manager(poetry: Poetry, io: BufferedIO) -> PluginManager:
80-
return PluginManager(Plugin.group, disable_plugins=True)
81-
82-
8378
def test_load_plugins_and_activate(
8479
manager_factory: ManagerFactory,
8580
poetry: Poetry,
@@ -114,15 +109,3 @@ def test_load_plugins_with_invalid_plugin(
114109

115110
with pytest.raises(ValueError):
116111
manager.load_plugins()
117-
118-
119-
def test_load_plugins_with_plugins_disabled(
120-
no_plugin_manager: PluginManager,
121-
poetry: Poetry,
122-
io: BufferedIO,
123-
with_my_plugin: None,
124-
) -> None:
125-
no_plugin_manager.load_plugins()
126-
127-
assert poetry.package.version.text == "1.2.3"
128-
assert io.fetch_output() == ""

0 commit comments

Comments
 (0)