| 
46 | 46 | from .wrap_modes import from_string as wrap_mode_from_string  | 
47 | 47 | 
 
  | 
48 | 48 | if TYPE_CHECKING:  | 
 | 49 | +    if sys.version_info < (3, 10):  # pragma: no cover  | 
 | 50 | +        EntryPoints = Any  | 
 | 51 | +    else:  | 
 | 52 | +        from importlib.metadata import EntryPoints  | 
 | 53 | + | 
49 | 54 |     tomllib: Any  | 
50 | 55 | else:  | 
51 | 56 |     if sys.version_info >= (3, 11):  | 
@@ -356,9 +361,7 @@ def __init__(  | 
356 | 361 |         profile: Dict[str, Any] = {}  | 
357 | 362 |         if profile_name:  | 
358 | 363 |             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"):  | 
362 | 365 |                     profiles.setdefault(plugin.name, plugin.load())  | 
363 | 366 | 
 
  | 
364 | 367 |             if profile_name not in profiles:  | 
@@ -473,9 +476,7 @@ def __init__(  | 
473 | 476 |             combined_config["src_paths"] = tuple(src_paths)  | 
474 | 477 | 
 
  | 
475 | 478 |         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"):  | 
479 | 480 |                 if plugin.name == combined_config["formatter"]:  | 
480 | 481 |                     combined_config["formatting_function"] = plugin.load()  | 
481 | 482 |                     break  | 
@@ -715,9 +716,7 @@ def sorting_function(self) -> Callable[..., List[str]]:  | 
715 | 716 |             self._sorting_function = sorted  | 
716 | 717 |         else:  | 
717 | 718 |             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"):  | 
721 | 720 |                 available_sort_orders.append(sort_plugin.name)  | 
722 | 721 |                 if sort_plugin.name == self.sort_order:  | 
723 | 722 |                     self._sorting_function = sort_plugin.load()  | 
@@ -938,4 +937,17 @@ def _as_bool(value: str) -> bool:  | 
938 | 937 |         raise ValueError(f"invalid truth value {value}")  | 
939 | 938 | 
 
  | 
940 | 939 | 
 
  | 
 | 940 | +def entry_points(group: str) -> "EntryPoints":  | 
 | 941 | +    """Call entry_point after lazy loading it.  | 
 | 942 | +
  | 
 | 943 | +    TODO: The reason for lazy loading here are unknown.  | 
 | 944 | +    """  | 
 | 945 | +    if sys.version_info < (3, 10):  # pragma: no cover  | 
 | 946 | +        from importlib_metadata import entry_points  | 
 | 947 | +    else:  | 
 | 948 | +        from importlib.metadata import entry_points  | 
 | 949 | + | 
 | 950 | +    return entry_points(group=group)  | 
 | 951 | + | 
 | 952 | + | 
941 | 953 | DEFAULT_CONFIG = Config()  | 
0 commit comments