Skip to content

Commit de5dc8a

Browse files
committed
Load plugins during init rather than on import
1 parent 83bba3b commit de5dc8a

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/pip/_internal/cli/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pip._internal.commands import create_command
1414
from pip._internal.exceptions import PipError
1515
from pip._internal.utils import deprecation
16+
from pip._internal.utils.plugins import load_plugins
1617

1718
logger = logging.getLogger(__name__)
1819

@@ -77,4 +78,6 @@ def main(args: Optional[List[str]] = None) -> int:
7778
logger.debug("Ignoring error %s when setting locale", e)
7879
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
7980

81+
load_plugins()
82+
8083
return command.main(cmd_args)

src/pip/_internal/utils/plugins.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from pip._internal.models.plugin import DistInspectorPlugin, Plugin, plugin_from_module
88

99
logger = logging.getLogger(__name__)
10-
1110
_loaded_plugins: List[Plugin] = []
1211

1312

@@ -24,15 +23,16 @@ def iter_entry_points(group_name: str) -> EntryPoints:
2423
return groups.get(group_name, [])
2524

2625

27-
for entrypoint in iter_entry_points(group_name="pip.plugins"):
28-
try:
29-
module = entrypoint.load()
30-
except ModuleNotFoundError:
31-
logger.warning("Tried to load plugin %s but failed", entrypoint.name)
32-
continue
33-
plugin = plugin_from_module(entrypoint.name, module)
34-
if plugin is not None:
35-
_loaded_plugins.append(plugin)
26+
def load_plugins() -> None:
27+
for entrypoint in iter_entry_points(group_name="pip.plugins"):
28+
try:
29+
module = entrypoint.load()
30+
except ModuleNotFoundError:
31+
logger.warning("Tried to load plugin %s but failed", entrypoint.name)
32+
continue
33+
plugin = plugin_from_module(entrypoint.name, module)
34+
if plugin is not None:
35+
_loaded_plugins.append(plugin)
3636

3737

3838
@contextlib.contextmanager

0 commit comments

Comments
 (0)