Skip to content

Commit

Permalink
refactor: use importlib instead of pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
sijis committed Oct 29, 2023
1 parent cb9e671 commit 0c6a993
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions errbot/repo_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def check_dependencies(req_path: Path) -> Tuple[Optional[str], Sequence[str]]:
log.debug("check dependencies of %s", req_path)
# noinspection PyBroadException
try:
from pkg_resources import get_distribution
from importlib.metadata import distribution

missing_pkg = []

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

# noinspection PyBroadException
try:
get_distribution(stripped)
distribution(stripped)
except Exception:
missing_pkg.append(stripped)
if missing_pkg:
Expand Down
15 changes: 11 additions & 4 deletions errbot/utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import collections
import fnmatch
import importlib.metadata
import inspect
import logging
import os
import pathlib
import re
import sys
import time
from functools import wraps
from platform import system
from typing import List, Tuple, Union

import pkg_resources
from dulwich import porcelain

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

def entry_point_plugins(group):
paths = []
for entry_point in pkg_resources.iter_entry_points(group):
ep = next(pkg_resources.iter_entry_points(group, entry_point.name))
paths.append(f"{ep.dist.module_path}/{entry_point.module_name}")

eps = importlib.metadata.entry_points()
for entry_point in eps.select(group=group):
module_name = entry_point.module
file_name = module_name.replace(".", "/") + ".py"
for f in entry_point.dist.files:
if file_name == str(f):
parent = str(pathlib.Path(f).resolve().parent)
paths.append(f"{parent}/{module_name}")
return paths


Expand Down

0 comments on commit 0c6a993

Please sign in to comment.