Skip to content

Commit

Permalink
Find entry_points with importlib(.|_)metadata, drop setuptools
Browse files Browse the repository at this point in the history
…from `dependencies` (#385)
  • Loading branch information
bollwyvl authored Aug 15, 2023
1 parent 15e2447 commit f47867a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
15 changes: 12 additions & 3 deletions pylsp/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -104,4 +104,3 @@ addopts = "--cov-report html --cov-report term --junitxml=pytest.xml --cov pylsp

[tool.coverage.run]
concurrency = ["multiprocessing", "thread"]

0 comments on commit f47867a

Please sign in to comment.