Skip to content

Commit

Permalink
Add logic to iterate over entrypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
facutuesca committed Oct 22, 2024
1 parent bc3d3f7 commit 0650be9
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/pip/_internal/utils/plugins.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import contextlib
import logging
from importlib.metadata import EntryPoints, entry_points
from pathlib import Path
from typing import Iterator, List

from pip._vendor.pygments.plugin import iter_entry_points

from pip._internal.models.plugin import DistInspectorPlugin, Plugin, plugin_from_module

logger = logging.getLogger(__name__)

_loaded_plugins: List[Plugin] = []


def iter_entry_points(group_name: str) -> EntryPoints:
groups = entry_points()
if hasattr(groups, "select"):
# New interface in Python 3.10 and newer versions of the
# importlib_metadata backport.
return groups.select(group=group_name)
else:
assert hasattr(groups, "get")
# Older interface, deprecated in Python 3.10 and recent
# importlib_metadata, but we need it in Python 3.8 and 3.9.
return groups.get(group_name, [])


for entrypoint in iter_entry_points(group_name="pip.plugins"):
try:
module = entrypoint.load()
Expand Down

0 comments on commit 0650be9

Please sign in to comment.