8000 Find `entry_points` with `importlib(.|_)metadata`, drop `setuptools` … · python-lsp/python-lsp-server@f47867a · GitHub
[go: up one dir, main page]

Skip to content

Commit f47867a

Browse files
authored
Find entry_points with importlib(.|_)metadata, drop setuptools from dependencies (#385)
1 parent 15e2447 commit f47867a

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

pylsp/config/config.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
# pylint: disable=import-outside-toplevel
44

55
import logging
6+
import sys
67
from functools import lru_cache
78
from typing import List, Mapping, Sequence, Union
89

9-
import pkg_resources
1010
import pluggy
1111
from pluggy._hooks import HookImpl
1212

1313
from pylsp import _utils, hookspecs, uris, PYLSP
1414

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+
1523
log = logging.getLogger(__name__)
1624

1725
# Sources of config, first source overrides next source
@@ -67,14 +75,15 @@ def __init__(self, root_uri, init_opts, process_id, capabilities):
6775
# Pluggy will skip loading a plugin if it throws a DistributionNotFound exception.
6876
# However I don't want all plugins to have to catch ImportError and re-throw. So here we'll filter
6977
# 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):
7179
try:
7280
entry_point.load()
7381
except Exception as e: # pylint: disable=broad-except
7482
log.info("Failed to load %s entry point '%s': %s", PYLSP, entry_point.name, e)
7583
self._pm.set_blocked(entry_point.name)
7684

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``.
7887
self._pm.load_setuptools_entrypoints(PYLSP)
7988

8089
for name, plugin in self._pm.list_name_plugin():

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ readme = "README.md"
1313
license = {text = "MIT"}
1414
requires-python = ">=3.8"
1515
dependencies = [
16+
"docstring-to-markdown",
17+
"importlib_metadata>=4.8.3;python_version<\"3.10\"",
1618
"jedi>=0.17.2,<0.20.0",
17-
"python-lsp-jsonrpc>=1.0.0",
1819
"pluggy>=1.0.0",
19-
"docstring-to-markdown",
20+
"python-lsp-jsonrpc>=1.0.0",
2021
"ujson>=3.0.0",
21-
"setuptools>=39.0.0",
2222
]
2323
dynamic = ["version"]
2424

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

105105
[tool.coverage.run]
106106
concurrency = ["multiprocessing", "thread"]
107-

0 commit comments

Comments
 (0)
0