Skip to content

Commit

Permalink
Use 'selectable' interface for entry points only when available (#2246)
Browse files Browse the repository at this point in the history
  • Loading branch information
hroncok committed Dec 27, 2021
1 parent 12a1fc2 commit bb82a73
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog/2246.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop the runtime dependency of ``backports.entry-points-selectable`` - by :user:`hroncok`.
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ project_urls =
[options]
packages = find:
install_requires =
backports.entry-points-selectable>=1.0.4
distlib>=0.3.1,<1
filelock>=3.2,<4
platformdirs>=2,<3
Expand Down
15 changes: 13 additions & 2 deletions src/virtualenv/run/plugin/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from __future__ import absolute_import, unicode_literals

import sys
from collections import OrderedDict

from backports.entry_points_selectable import entry_points
if sys.version_info >= (3, 8):
from importlib.metadata import entry_points

importlib_metadata_version = ()
else:
from importlib_metadata import entry_points, version

importlib_metadata_version = tuple(int(i) for i in version("importlib_metadata").split(".")[:2])


class PluginLoader(object):
Expand All @@ -11,7 +19,10 @@ class PluginLoader(object):

@classmethod
def entry_points_for(cls, key):
return OrderedDict((e.name, e.load()) for e in cls.entry_points().select(group=key))
if sys.version_info >= (3, 10) or importlib_metadata_version >= (3, 6):
return OrderedDict((e.name, e.load()) for e in cls.entry_points().select(group=key))
else:
return OrderedDict((e.name, e.load()) for e in cls.entry_points().get(key, {}))

@staticmethod
def entry_points():
Expand Down

0 comments on commit bb82a73

Please sign in to comment.