Skip to content

Commit

Permalink
refactor: remove unused parameters from plugin manager (python-poetry…
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Jul 14, 2024
1 parent b661c1a commit 56a557e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 35 deletions.
7 changes: 4 additions & 3 deletions src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 10 additions & 15 deletions src/poetry/plugins/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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)
Expand All @@ -58,18 +53,18 @@ 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"
)

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)

Expand All @@ -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())
17 changes: 0 additions & 17 deletions tests/plugins/test_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() == ""

0 comments on commit 56a557e

Please sign in to comment.