From: Sijis Aviles Date: Fri, 13 Jun 2025 13:50:39 -0500 Subject: fix: importlib refactor (#1733) * fix: importlib refactor Simplify logic and exclude cache directories. * test: adjust and consolidate entry_point tests * docs: add info to CHANGES Origin: backport, https://github.com/errbotio/errbot/pull/1733 Bug-Debian: https://bugs.debian.org/1083380 Last-Update: 2026-01-06 --- errbot/utils.py | 16 ++++++---------- tests/plugin_entrypoint_test.py | 18 ------------------ tests/utils_test.py | 9 ++++++++- 3 files changed, 14 insertions(+), 29 deletions(-) delete mode 100644 tests/plugin_entrypoint_test.py --- a/errbot/utils.py +++ b/errbot/utils.py @@ -4,7 +4,6 @@ import inspect import logging import os -import pathlib import re import sys import time @@ -199,7 +198,7 @@ def entry_point_plugins(group): - paths = [] + paths = set() eps = importlib.metadata.entry_points() try: @@ -209,8 +208,6 @@ entry_points = eps.get(group, ()) for entry_point in entry_points: - module_name = entry_point.module - file_name = module_name.replace(".", "/") + ".py" try: files = entry_point.dist.files except AttributeError: @@ -220,12 +217,11 @@ except importlib.metadata.PackageNotFoundError: # entrypoint is not a distribution, so let's skip looking for files continue - - for f in files: - if file_name == str(f): - parent = str(pathlib.Path(f).resolve().parent) - paths.append(f"{parent}/{module_name}") - return paths + for file in files: + if "__pycache__" not in file.parts: + parent = file.locate().absolute().resolve().parent + paths.add(str(parent)) + return list(paths) def global_restart() -> None: --- a/tests/plugin_entrypoint_test.py +++ /dev/null @@ -1,18 +0,0 @@ -from errbot.utils import entry_point_plugins - - -def test_entrypoint_paths(): - plugins = entry_point_plugins("console_scripts") - - match = False - for plugin in plugins: - if "errbot/errbot.cli" in plugin: - match = True - assert match - - -def test_entrypoint_paths_empty(): - groups = ["errbot.plugins", "errbot.backend_plugins"] - for entry_point_group in groups: - plugins = entry_point_plugins(entry_point_group) - assert plugins == [] --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -119,6 +119,13 @@ results = entry_point_plugins("console_scripts") match = False for result in results: - if result.endswith("errbot/errbot.cli"): + if "errbot" in result: match = True assert match + + +def test_entry_point_paths_empty(): + groups = ["errbot.plugins", "errbot.backend_plugins"] + for entry_point_group in groups: + plugins = entry_point_plugins(entry_point_group) + assert plugins == [] --- a/setup.py +++ b/setup.py @@ -28,7 +28,6 @@ deps = [ "webtest==3.0.0", - "setuptools==68.1.2", "flask", "requests==2.31.0", "jinja2==3.1.2",