diff --git a/pylsp/config/config.py b/pylsp/config/config.py index f5de6f4d..76258600 100644 --- a/pylsp/config/config.py +++ b/pylsp/config/config.py @@ -3,15 +3,23 @@ # pylint: disable=import-outside-toplevel import logging +import sys from functools import lru_cache from typing import List, Mapping, Sequence, Union -import pkg_resources import pluggy from pluggy._hooks import HookImpl from pylsp import _utils, hookspecs, uris, PYLSP +# See compatibility note on `group` keyword: +# https://docs.python.org/3/library/importlib.metadata.html#entry-points +if sys.version_info < (3, 10): # pragma: no cover + from importlib_metadata import entry_points +else: # pragma: no cover + from importlib.metadata import entry_points + + log = logging.getLogger(__name__) # Sources of config, first source overrides next source @@ -67,14 +75,15 @@ def __init__(self, root_uri, init_opts, process_id, capabilities): # Pluggy will skip loading a plugin if it throws a DistributionNotFound exception. # However I don't want all plugins to have to catch ImportError and re-throw. So here we'll filter # out any entry points that throw ImportError assuming one or more of their dependencies isn't present. - for entry_point in pkg_resources.iter_entry_points(PYLSP): + for entry_point in entry_points(group=PYLSP): try: entry_point.load() except Exception as e: # pylint: disable=broad-except log.info("Failed to load %s entry point '%s': %s", PYLSP, entry_point.name, e) self._pm.set_blocked(entry_point.name) - # Load the entry points into pluggy, having blocked any failing ones + # Load the entry points into pluggy, having blocked any failing ones. + # Despite the API name, recent Pluggy versions will use ``importlib_metadata``. self._pm.load_setuptools_entrypoints(PYLSP) for name, plugin in self._pm.list_name_plugin(): diff --git a/pyproject.toml b/pyproject.toml index 289d8bf5..0a5fd202 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,12 +13,12 @@ readme = "README.md" license = {text = "MIT"} requires-python = ">=3.8" dependencies = [ + "docstring-to-markdown", + "importlib_metadata>=4.8.3;python_version<\"3.10\"", "jedi>=0.17.2,<0.20.0", - "python-lsp-jsonrpc>=1.0.0", "pluggy>=1.0.0", - "docstring-to-markdown", + "python-lsp-jsonrpc>=1.0.0", "ujson>=3.0.0", - "setuptools>=39.0.0", ] dynamic = ["version"] @@ -104,4 +104,3 @@ addopts = "--cov-report html --cov-report term --junitxml=pytest.xml --cov pylsp [tool.coverage.run] concurrency = ["multiprocessing", "thread"] -