Skip to content

Commit 83bba3b

Browse files
committed
Add logic to iterate over entrypoints
1 parent 358d887 commit 83bba3b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/pip/_internal/utils/plugins.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
import contextlib
22
import logging
3+
from importlib.metadata import EntryPoints, entry_points
34
from pathlib import Path
45
from typing import Iterator, List
56

6-
from pip._vendor.pygments.plugin import iter_entry_points
7-
87
from pip._internal.models.plugin import DistInspectorPlugin, Plugin, plugin_from_module
98

109
logger = logging.getLogger(__name__)
1110

1211
_loaded_plugins: List[Plugin] = []
12+
13+
14+
def iter_entry_points(group_name: str) -> EntryPoints:
15+
groups = entry_points()
16+
if hasattr(groups, "select"):
17+
# New interface in Python 3.10 and newer versions of the
18+
# importlib_metadata backport.
19+
return groups.select(group=group_name)
20+
else:
21+
assert hasattr(groups, "get")
22+
# Older interface, deprecated in Python 3.10 and recent
23+
# importlib_metadata, but we need it in Python 3.8 and 3.9.
24+
return groups.get(group_name, [])
25+
26+
1327
for entrypoint in iter_entry_points(group_name="pip.plugins"):
1428
try:
1529
module = entrypoint.load()

0 commit comments

Comments
 (0)