Skip to content

Commit

Permalink
plugin manager: use system env paths for discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Apr 19, 2022
1 parent 0a6e2f8 commit 92c3986
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/poetry/console/commands/self/show/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ def _system_project_handle(self) -> int:
}
)

entry_points = (
PluginManager(ApplicationPlugin.group).get_plugin_entry_points()
+ PluginManager(Plugin.group).get_plugin_entry_points()
)

system_env = EnvManager.get_system_env(naive=True)
entry_points = PluginManager(ApplicationPlugin.group).get_plugin_entry_points(
env=system_env
) + PluginManager(Plugin.group).get_plugin_entry_points(env=system_env)
installed_repository = InstalledRepository.load(
system_env, with_dependencies=True
)
Expand Down
21 changes: 16 additions & 5 deletions src/poetry/plugins/plugin_manager.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
from __future__ import annotations

import logging
import sys

from typing import Any
from typing import TYPE_CHECKING

import entrypoints

from poetry.plugins.application_plugin import ApplicationPlugin
from poetry.plugins.plugin import Plugin


if TYPE_CHECKING:
from typing import Any

from poetry.utils.env import Env


logger = logging.getLogger(__name__)


Expand All @@ -23,17 +30,21 @@ def __init__(self, group: str, disable_plugins: bool = False) -> None:
self._disable_plugins = disable_plugins
self._plugins: list[Plugin] = []

def load_plugins(self) -> None:
def load_plugins(self, env: Env | None = None) -> None:
if self._disable_plugins:
return

plugin_entrypoints = self.get_plugin_entry_points()
plugin_entrypoints = self.get_plugin_entry_points(env=env)

for entrypoint in plugin_entrypoints:
self._load_plugin_entrypoint(entrypoint)

def get_plugin_entry_points(self) -> list[entrypoints.EntryPoint]:
return entrypoints.get_group_all(self._group)
def get_plugin_entry_points(
self, env: Env | None = None
) -> list[entrypoints.EntryPoint]:
return entrypoints.get_group_all(
self._group, path=env.sys_path if env else sys.path
)

def add_plugin(self, plugin: Plugin) -> None:
if not isinstance(plugin, (Plugin, ApplicationPlugin)):
Expand Down

0 comments on commit 92c3986

Please sign in to comment.