Skip to content

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

@juliangilbey

Description

@juliangilbey

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions