Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use importlib instead of pkg_resources #1669

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading