Skip to content

Commit fe1d117

Browse files
committed
Drop use of non-standard pkg_resources API
Use the canonical `importlib.metadata.entry_points` instead. Fix #2404
1 parent dab66ce commit fe1d117

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

isort/settings.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
from .wrap_modes import WrapModes
4646
from .wrap_modes import from_string as wrap_mode_from_string
4747

48+
if sys.version_info < (3, 10):
49+
from importlib_metadata import entry_points
50+
else:
51+
from importlib.metadata import entry_points
52+
4853
if TYPE_CHECKING:
4954
tomllib: Any
5055
else:
@@ -356,9 +361,7 @@ def __init__(
356361
profile: Dict[str, Any] = {}
357362
if profile_name:
358363
if profile_name not in profiles:
359-
import pkg_resources
360-
361-
for plugin in pkg_resources.iter_entry_points("isort.profiles"):
364+
for plugin in entry_points(group="isort.profiles"):
362365
profiles.setdefault(plugin.name, plugin.load())
363366

364367
if profile_name not in profiles:
@@ -473,9 +476,7 @@ def __init__(
473476
combined_config["src_paths"] = tuple(src_paths)
474477

475478
if "formatter" in combined_config:
476-
import pkg_resources
477-
478-
for plugin in pkg_resources.iter_entry_points("isort.formatters"):
479+
for plugin in entry_points(group="isort.formatters"):
479480
if plugin.name == combined_config["formatter"]:
480481
combined_config["formatting_function"] = plugin.load()
481482
break
@@ -715,9 +716,7 @@ def sorting_function(self) -> Callable[..., List[str]]:
715716
self._sorting_function = sorted
716717
else:
717718
available_sort_orders = ["natural", "native"]
718-
import pkg_resources
719-
720-
for sort_plugin in pkg_resources.iter_entry_points("isort.sort_function"):
719+
for sort_plugin in entry_points(group="isort.sort_function"):
721720
available_sort_orders.append(sort_plugin.name)
722721
if sort_plugin.name == self.sort_order:
723722
self._sorting_function = sort_plugin.load()

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ include = [
3838
]
3939
requires-python = ">=3.9.0"
4040

41-
dependencies = []
41+
dependencies = [
42+
"importlib_metadata; python_version < '3.10'",
43+
]
4244

4345
[project.urls]
4446
Homepage = "https://pycqa.github.io/isort/index.html"

0 commit comments

Comments
 (0)