Skip to content
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

Migrate from pkg_resources to importlib.metadata in tests/test_plugin.py #62

Open
juliangilbey opened this issue Nov 20, 2024 · 0 comments

Comments

@juliangilbey
Copy link

juliangilbey commented Nov 20, 2024

According to https://setuptools.pypa.io/en/latest/pkg_resources.html, pkg_resources is deprecated in favour of importlib.metadata. Unfortunately, though, the semantics of the entry_points() function changed in Python 3.10. So once support for Pythons 3.8 and 3.9 is dropped in python-lsp-black, this could be migrated to the preferred importlib.metadata tools. (One could have a conditional for Python >= 3.10 in the meantime, but that would be ugly.)

Here is a patch that should work on Python 3.10+:

--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -2,10 +2,10 @@
 import types
 from pathlib import Path
 from unittest.mock import Mock
+from importlib.metadata import entry_points
 
 # Third-party imports
 import black
-import pkg_resources
 import pytest
 
 # Python LSP imports
@@ -321,8 +321,7 @@
 
 
 def test_entry_point():
-    distribution = pkg_resources.get_distribution("python-lsp-black")
-    entry_point = distribution.get_entry_info("pylsp", "black")
+    (entry_point,) = entry_points(group="pylsp", name="black")
 
     assert entry_point is not None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant