diff --git a/src/pip/_internal/cli/main.py b/src/pip/_internal/cli/main.py index 563ac79c984..00637ef182c 100644 --- a/src/pip/_internal/cli/main.py +++ b/src/pip/_internal/cli/main.py @@ -13,6 +13,7 @@ from pip._internal.commands import create_command from pip._internal.exceptions import PipError from pip._internal.utils import deprecation +from pip._internal.utils.plugins import load_plugins logger = logging.getLogger(__name__) @@ -77,4 +78,6 @@ def main(args: Optional[List[str]] = None) -> int: logger.debug("Ignoring error %s when setting locale", e) command = create_command(cmd_name, isolated=("--isolated" in cmd_args)) + load_plugins() + return command.main(cmd_args) diff --git a/src/pip/_internal/utils/plugins.py b/src/pip/_internal/utils/plugins.py index 697910324d9..cb0408af935 100644 --- a/src/pip/_internal/utils/plugins.py +++ b/src/pip/_internal/utils/plugins.py @@ -7,7 +7,6 @@ from pip._internal.models.plugin import DistInspectorPlugin, Plugin, plugin_from_module logger = logging.getLogger(__name__) - _loaded_plugins: List[Plugin] = [] @@ -24,15 +23,16 @@ def iter_entry_points(group_name: str) -> EntryPoints: return groups.get(group_name, []) -for entrypoint in iter_entry_points(group_name="pip.plugins"): - try: - module = entrypoint.load() - except ModuleNotFoundError: - logger.warning("Tried to load plugin %s but failed", entrypoint.name) - continue - plugin = plugin_from_module(entrypoint.name, module) - if plugin is not None: - _loaded_plugins.append(plugin) +def load_plugins() -> None: + for entrypoint in iter_entry_points(group_name="pip.plugins"): + try: + module = entrypoint.load() + except ModuleNotFoundError: + logger.warning("Tried to load plugin %s but failed", entrypoint.name) + continue + plugin = plugin_from_module(entrypoint.name, module) + if plugin is not None: + _loaded_plugins.append(plugin) @contextlib.contextmanager