Use 'selectable' interface for entry points only when available (#2246)
This commit is contained in:
parent
12a1fc2860
commit
bb82a73b6d
3 changed files with 14 additions and 3 deletions
1
docs/changelog/2246.feature.rst
Normal file
1
docs/changelog/2246.feature.rst
Normal file
|
|
@ -0,0 +1 @@
|
|||
Drop the runtime dependency of ``backports.entry-points-selectable`` - by :user:`hroncok`.
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Reference in a new issue