8000 Find `entry_points` with `importlib(.|_)metadata`, drop `setuptools` from `dependencies` by bollwyvl · Pull Request #385 · python-lsp/python-lsp-server · GitHub
[go: up one dir, main page]

Skip to content

Find entry_points with importlib(.|_)metadata, drop setuptools from dependencies #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2023

Conversation

bollwyvl
Copy link
Contributor

References

Changes

  • remove runtime dependency on setuptools (only used for entry_point discovery)
  • use importlib_metdata on python <3.10
  • use stdlib importlib.metadata on python 3.10+
  • add note that pluggy does the same

@pkulev
Copy link
Contributor
pkulev commented Jun 29, 2023

https://docs.python.org/3.8/library/importlib.metadata.html#entry-points

It seems that from importlib.metadata import entry_points will work even before 3.10.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that from importlib.metadata import entry_points will work even before 3.10.

Reproduced here from this link, emphasis mine:

The “selectable” entry points were introduced in importlib_metadata 3.6 and Python 3.10. Prior to those changes, entry_points accepted no parameters and always returned a dictionary of entry points, keyed by group. For compatibility, if no parameters are passed to entry_points, a SelectableGroups object is returned, implementing that dict interface. In the future, calling entry_points with no parameters will return an EntryPoints object. Users should rely on the selection interface to retrieve entry points by group.

Before 3.10 stdlib, and older importlib_metadata, all of the entry_points in $PREFIX/lib/python-3* are discovered and parsed without any kind of cache. In a large environment, this can take a number of seconds. The venerable entrypoints did this a bit better, but is now deprecated, leaving this half-measure until 3.9 EOL to avoid getting bitten by inconsistent return types and performance cliffs.

@ccordoba12 ccordoba12 changed the title find entry_points with importlib(.|_)metadata, drop setuptools from dependencies Find entry_points with importlib(.|_)metadata, drop setuptools from dependencies Jun 29, 2023
@ccordoba12 ccordoba12 added this to the v1.7.4 milestone Jun 29, 2023
@ccordoba12 ccordoba12 closed this Jun 29, 2023
@ccordoba12 ccordoba12 reopened this Jun 29, 2023
@ccordoba12
Copy link
Member
ccordoba12 commented Jun 29, 2023

It seems this requires dropping support for Python 3.7, so I'm going to leave it for 1.8.0.

@ccordoba12 ccordoba12 modified the milestones: v1.7.4, v1.8.0 Jun 29, 2023
@bollwyvl
Copy link
Contributor Author

requires dropping support for Python 3.7, so I'm going to leave it for 1.8.0.

    python-lsp-server[all,test] 0.1.dev1+gd8a39c0 depends on importlib-metadata>=4.8.3; python_version < "3.10"
    flake8 5.0.4 depends on importlib-metadata<4.3 and >=1.1.0; python_version < "3.8"
    python-lsp-server[all,test] 0.1.dev1+gd8a39c0 depends on importlib-metadata>=4.8.3; python_version < "3.10"
    flake8 5.0.3 depends on importlib-metadata<4.3; python_version < "3.8"
    python-lsp-server[all,test] 0.1.dev1+gd8a39c0 depends on importlib-metadata>=4.8.3; python_version < "3.10"
    flake8 5.0.2 depends on importlib-metadata<4.3; python_version < "3.8"
    python-lsp-server[all,test] 0.1.dev1+gd8a39c0 depends on importlib-metadata>=4.8.3; python_version < "3.10"
    flake8 5.0.1 depends on importlib-metadata<4.3; python_version < "3.8"
    python-lsp-server[all,test] 0.1.dev1+gd8a39c0 depends on importlib-metadata>=4.8.3; python_version < "3.10"
    flake8 5.0.0 depends on importlib-metadata<4.3; python_version < "3.8"

oh, flake8, you're so annoying.

@ccordoba12
Copy link
Member

@bollwyvl, I dropped support for Python 3.7 in PR #417. So, please rebase or merge with master so we can merge this one.

@bollwyvl
Copy link
Contributor Author

re ⚾ d

Copy link
Member
@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bollwyvl for your help with this!

@ccordoba12 ccordoba12 merged commit f47867a into python-lsp:develop Aug 15, 2023
@bollwyvl bollwyvl deleted the gh-384-importlib branch August 15, 2023 14:44
tkrabel-db pushed a commit to tkrabel-db/python-lsp-server that referenced this pull request Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace setuptools/pkg_resources with importlib(.|_)metadata
3 participants
0