From b079c5e606d4b2265eae9d8a1b999a4d245f930e Mon Sep 17 00:00:00 2001 From: Sijis Aviles Date: Fri, 6 Jun 2025 15:47:29 -0500 Subject: [PATCH 1/3] fix: importlib refactor Simplify logic and exclude cache directories. --- errbot/utils.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/errbot/utils.py b/errbot/utils.py index 658e80137..bc16d5ee9 100644 --- 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 collect_roots(base_paths: List, file_sig: str = "*.plug") -> List: def entry_point_plugins(group): - paths = [] + paths = set() eps = importlib.metadata.entry_points() try: @@ -209,8 +208,6 @@ def entry_point_plugins(group): 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 @@ def entry_point_plugins(group): 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: From a7a37b6433d258ed5888c5ca77d23cd646674674 Mon Sep 17 00:00:00 2001 From: Sijis Aviles Date: Sat, 7 Jun 2025 03:47:13 -0500 Subject: [PATCH 2/3] test: adjust and consolidate entry_point tests --- tests/plugin_entrypoint_test.py | 18 ------------------ tests/utils_test.py | 9 ++++++++- 2 files changed, 8 insertions(+), 19 deletions(-) delete mode 100644 tests/plugin_entrypoint_test.py diff --git a/tests/plugin_entrypoint_test.py b/tests/plugin_entrypoint_test.py deleted file mode 100644 index 9a9d499c0..000000000 --- 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 == [] diff --git a/tests/utils_test.py b/tests/utils_test.py index 92ec25bc2..b9039db46 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -118,6 +118,13 @@ def test_entry_point_plugins_valid_groups(): 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 == [] From 901cd686127175a0ae12e11f1fdafea7e4369401 Mon Sep 17 00:00:00 2001 From: Sijis Aviles Date: Thu, 12 Jun 2025 23:01:06 -0500 Subject: [PATCH 3/3] docs: add info to CHANGES --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index f0cafd81c..8c98924e2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -28,7 +28,7 @@ fixes: - fix: add extra_plugin_dir support to FullStackTest (#1726) - fix: add missing py 3.13 in tox (#1731) - fix: add filter to tar extract (#1730) -- refactor: use importlib to find plugins in entry_points (#1669) +- refactor: use importlib to find plugins in entry_points (#1669, #1733) v6.2.0 (2024-01-01)