Skip to content

Commit

Permalink
Load plugins during init rather than on import
Browse files Browse the repository at this point in the history
  • Loading branch information
facutuesca committed Oct 18, 2024
1 parent 83bba3b commit de5dc8a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/pip/_internal/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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)
20 changes: 10 additions & 10 deletions src/pip/_internal/utils/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pip._internal.models.plugin import DistInspectorPlugin, Plugin, plugin_from_module

logger = logging.getLogger(__name__)

_loaded_plugins: List[Plugin] = []


Expand All @@ -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
Expand Down

0 comments on commit de5dc8a

Please sign in to comment.