From 56a557e305bf0417ff3d4029b96b273af15c8aa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Sat, 29 Jun 2024 17:17:05 +0200 Subject: [PATCH] refactor: remove unused parameters from plugin manager (#9547) --- src/poetry/factory.py | 7 ++++--- src/poetry/plugins/plugin_manager.py | 25 ++++++++++--------------- tests/plugins/test_plugin_manager.py | 17 ----------------- 3 files changed, 14 insertions(+), 35 deletions(-) diff --git a/src/poetry/factory.py b/src/poetry/factory.py index 4cfcd91d060..d627c537251 100644 --- a/src/poetry/factory.py +++ b/src/poetry/factory.py @@ -99,9 +99,10 @@ def create_poetry( ) ) - plugin_manager = PluginManager(Plugin.group, disable_plugins=disable_plugins) - plugin_manager.load_plugins() - plugin_manager.activate(poetry, io) + if not disable_plugins: + plugin_manager = PluginManager(Plugin.group) + plugin_manager.load_plugins() + plugin_manager.activate(poetry, io) return poetry diff --git a/src/poetry/plugins/plugin_manager.py b/src/poetry/plugins/plugin_manager.py index 4ab286c36f7..bc1861411f9 100644 --- a/src/poetry/plugins/plugin_manager.py +++ b/src/poetry/plugins/plugin_manager.py @@ -7,13 +7,12 @@ from poetry.plugins.application_plugin import ApplicationPlugin from poetry.plugins.plugin import Plugin from poetry.utils._compat import metadata +from poetry.utils.env import Env if TYPE_CHECKING: from typing import Any - from poetry.utils.env import Env - logger = logging.getLogger(__name__) @@ -23,16 +22,12 @@ class PluginManager: This class registers and activates plugins. """ - def __init__(self, group: str, disable_plugins: bool = False) -> None: + def __init__(self, group: str) -> None: self._group = group - self._disable_plugins = disable_plugins self._plugins: list[Plugin] = [] - def load_plugins(self, env: Env | None = None) -> None: - if self._disable_plugins: - return - - plugin_entrypoints = self.get_plugin_entry_points(env=env) + def load_plugins(self) -> None: + plugin_entrypoints = self.get_plugin_entry_points() for ep in plugin_entrypoints: self._load_plugin_entry_point(ep) @@ -58,7 +53,11 @@ def get_plugin_entry_points( if self._is_plugin_candidate(ep, env) ] - def add_plugin(self, plugin: Plugin) -> None: + def activate(self, *args: Any, **kwargs: Any) -> None: + for plugin in self._plugins: + plugin.activate(*args, **kwargs) + + def _add_plugin(self, plugin: Plugin) -> None: if not isinstance(plugin, (Plugin, ApplicationPlugin)): raise ValueError( "The Poetry plugin must be an instance of Plugin or ApplicationPlugin" @@ -66,10 +65,6 @@ def add_plugin(self, plugin: Plugin) -> None: self._plugins.append(plugin) - def activate(self, *args: Any, **kwargs: Any) -> None: - for plugin in self._plugins: - plugin.activate(*args, **kwargs) - def _load_plugin_entry_point(self, ep: metadata.EntryPoint) -> None: logger.debug("Loading the %s plugin", ep.name) @@ -80,4 +75,4 @@ def _load_plugin_entry_point(self, ep: metadata.EntryPoint) -> None: "The Poetry plugin must be an instance of Plugin or ApplicationPlugin" ) - self.add_plugin(plugin()) + self._add_plugin(plugin()) diff --git a/tests/plugins/test_plugin_manager.py b/tests/plugins/test_plugin_manager.py index 44e0d68343d..67e4b6040b7 100644 --- a/tests/plugins/test_plugin_manager.py +++ b/tests/plugins/test_plugin_manager.py @@ -75,11 +75,6 @@ def _manager(group: str = Plugin.group) -> PluginManager: return _manager -@pytest.fixture() -def no_plugin_manager(poetry: Poetry, io: BufferedIO) -> PluginManager: - return PluginManager(Plugin.group, disable_plugins=True) - - def test_load_plugins_and_activate( manager_factory: ManagerFactory, poetry: Poetry, @@ -114,15 +109,3 @@ def test_load_plugins_with_invalid_plugin( with pytest.raises(ValueError): manager.load_plugins() - - -def test_load_plugins_with_plugins_disabled( - no_plugin_manager: PluginManager, - poetry: Poetry, - io: BufferedIO, - with_my_plugin: None, -) -> None: - no_plugin_manager.load_plugins() - - assert poetry.package.version.text == "1.2.3" - assert io.fetch_output() == ""