Use importlib_metadata for entry points

This commit is contained in:
Ines Montani 2019-10-07 00:03:27 +02:00
parent 5ed8c03afa
commit 9f071f5c40
4 changed files with 12 additions and 3 deletions

View File

@ -11,6 +11,7 @@ numpy>=1.15.0
requests>=2.13.0,<3.0.0
plac<1.0.0,>=0.9.6
pathlib==1.0.1; python_version < "3.4"
importlib_metadata>=0.23; python_version < "3.8"
# Optional dependencies
jsonschema>=2.6.0,<3.1.0
# Development dependencies

View File

@ -50,6 +50,7 @@ install_requires =
wasabi>=0.2.0,<1.1.0
srsly>=0.1.0,<1.1.0
pathlib==1.0.1; python_version < "3.4"
importlib_metadata>=0.23; python_version < "3.8"
[options.extras_require]
lookups =

View File

@ -35,6 +35,11 @@ try:
except ImportError:
cupy = None
try: # Python 3.8
import importlib.metadata as importlib_metadata
except ImportError:
import importlib_metadata # noqa: F401
try:
from thinc.neural.optimizers import Optimizer # noqa: F401
except ImportError:

View File

@ -27,7 +27,7 @@ except ImportError:
from .symbols import ORTH
from .compat import cupy, CudaStream, path2str, basestring_, unicode_
from .compat import import_file
from .compat import import_file, importlib_metadata
from .errors import Errors, Warnings, deprecation_warning
@ -283,7 +283,8 @@ def get_entry_points(key):
RETURNS (dict): Entry points, keyed by name.
"""
result = {}
for entry_point in pkg_resources.iter_entry_points(key):
eps = importlib_metadata.entry_points()
for entry_point in eps.get(key, []):
result[entry_point.name] = entry_point.load()
return result
@ -297,7 +298,8 @@ def get_entry_point(key, value, default=None):
default: Optional default value to return.
RETURNS: The loaded entry point or None.
"""
for entry_point in pkg_resources.iter_entry_points(key):
eps = importlib_metadata.entry_points()
for entry_point in eps.get(key, []):
if entry_point.name == value:
return entry_point.load()
return default