Skip to content

Commit 26297d9

Browse files
committed
refactor: use importlib instead of pkg_resources
1 parent cbfc29f commit 26297d9

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

errbot/repo_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def check_dependencies(req_path: Path) -> Tuple[Optional[str], Sequence[str]]:
9393
log.debug("check dependencies of %s", req_path)
9494
# noinspection PyBroadException
9595
try:
96-
from pkg_resources import get_distribution
96+
from importlib.metadata import distribution
9797

9898
missing_pkg = []
9999

@@ -110,7 +110,7 @@ def check_dependencies(req_path: Path) -> Tuple[Optional[str], Sequence[str]]:
110110

111111
# noinspection PyBroadException
112112
try:
113-
get_distribution(stripped)
113+
distribution(stripped)
114114
except Exception:
115115
missing_pkg.append(stripped)
116116
if missing_pkg:

errbot/utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import collections
22
import fnmatch
3+
import importlib.metadata
34
import inspect
45
import logging
56
import os
7+
import pathlib
68
import re
79
import sys
810
import time
911
from functools import wraps
1012
from platform import system
1113
from typing import List, Tuple, Union
1214

13-
import pkg_resources
1415
from dulwich import porcelain
1516

1617
log = logging.getLogger(__name__)
@@ -199,9 +200,15 @@ def collect_roots(base_paths: List, file_sig: str = "*.plug") -> List:
199200

200201
def entry_point_plugins(group):
201202
paths = []
202-
for entry_point in pkg_resources.iter_entry_points(group):
203-
ep = next(pkg_resources.iter_entry_points(group, entry_point.name))
204-
paths.append(f"{ep.dist.module_path}/{entry_point.module_name}")
203+
204+
eps = importlib.metadata.entry_points()
205+
for entry_point in eps.select(group=group):
206+
module_name = entry_point.module
207+
file_name = module_name.replace(".", "/") + ".py"
208+
for f in entry_point.dist.files:
209+
if file_name == str(f):
210+
parent = str(pathlib.Path(f).resolve().parent)
211+
paths.append(f"{parent}/{module_name}")
205212
return paths
206213

207214

0 commit comments

Comments
 (0)