|
3 | 3 | # pylint: disable=import-outside-toplevel
|
4 | 4 |
|
5 | 5 | import logging
|
| 6 | +import sys |
6 | 7 | from functools import lru_cache
|
7 | 8 | from typing import List, Mapping, Sequence, Union
|
8 | 9 |
|
9 |
| -import pkg_resources |
10 | 10 | import pluggy
|
11 | 11 | from pluggy._hooks import HookImpl
|
12 | 12 |
|
13 | 13 | from pylsp import _utils, hookspecs, uris, PYLSP
|
14 | 14 |
|
| 15 | +# See compatibility note on `group` keyword: |
| 16 | +# https://docs.python.org/3/library/importlib.metadata.html#entry-points |
| 17 | +if sys.version_info < (3, 10): # pragma: no cover |
| 18 | + from importlib_metadata import entry_points |
| 19 | +else: # pragma: no cover |
| 20 | + from importlib.metadata import entry_points |
| 21 | + |
| 22 | + |
15 | 23 | log = logging.getLogger(__name__)
|
16 | 24 |
|
17 | 25 | # Sources of config, first source overrides next source
|
@@ -67,14 +75,15 @@ def __init__(self, root_uri, init_opts, process_id, capabilities):
|
67 | 75 | # Pluggy will skip loading a plugin if it throws a DistributionNotFound exception.
|
68 | 76 | # However I don't want all plugins to have to catch ImportError and re-throw. So here we'll filter
|
69 | 77 | # out any entry points that throw ImportError assuming one or more of their dependencies isn't present.
|
70 |
| - for entry_point in pkg_resources.iter_entry_points(PYLSP): |
| 78 | + for entry_point in entry_points(group=PYLSP): |
71 | 79 | try:
|
72 | 80 | entry_point.load()
|
73 | 81 | except Exception as e: # pylint: disable=broad-except
|
74 | 82 | log.info("Failed to load %s entry point '%s': %s", PYLSP, entry_point.name, e)
|
75 | 83 | self._pm.set_blocked(entry_point.name)
|
76 | 84 |
|
77 |
| - # Load the entry points into pluggy, having blocked any failing ones |
| 85 | + # Load the entry points into pluggy, having blocked any failing ones. |
| 86 | + # Despite the API name, recent Pluggy versions will use ``importlib_metadata``. |
78 | 87 | self._pm.load_setuptools_entrypoints(PYLSP)
|
79 | 88 |
|
80 | 89 | for name, plugin in self._pm.list_name_plugin():
|
|