Skip to content

Commit f309c57

Browse files
authored
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
1 parent 363f01f commit f309c57

File tree

4 files changed

+15
-30
lines changed

4 files changed

+15
-30
lines changed

CHANGES.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fixes:
2828
- fix: add extra_plugin_dir support to FullStackTest (#1726)
2929
- fix: add missing py 3.13 in tox (#1731)
3030
- fix: add filter to tar extract (#1730)
31-
- refactor: use importlib to find plugins in entry_points (#1669)
31+
- refactor: use importlib to find plugins in entry_points (#1669, #1733)
3232

3333

3434
v6.2.0 (2024-01-01)

errbot/utils.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import inspect
55
import logging
66
import os
7-
import pathlib
87
import re
98
import sys
109
import time
@@ -199,7 +198,7 @@ def collect_roots(base_paths: List, file_sig: str = "*.plug") -> List:
199198

200199

201200
def entry_point_plugins(group):
202-
paths = []
201+
paths = set()
203202

204203
eps = importlib.metadata.entry_points()
205204
try:
@@ -209,8 +208,6 @@ def entry_point_plugins(group):
209208
entry_points = eps.get(group, ())
210209

211210
for entry_point in entry_points:
212-
module_name = entry_point.module
213-
file_name = module_name.replace(".", "/") + ".py"
214211
try:
215212
files = entry_point.dist.files
216213
except AttributeError:
@@ -220,12 +217,11 @@ def entry_point_plugins(group):
220217
except importlib.metadata.PackageNotFoundError:
221218
# entrypoint is not a distribution, so let's skip looking for files
222219
continue
223-
224-
for f in files:
225-
if file_name == str(f):
226-
parent = str(pathlib.Path(f).resolve().parent)
227-
paths.append(f"{parent}/{module_name}")
228-
return paths
220+
for file in files:
221+
if "__pycache__" not in file.parts:
222+
parent = file.locate().absolute().resolve().parent
223+
paths.add(str(parent))
224+
return list(paths)
229225

230226

231227
def global_restart() -> None:

tests/plugin_entrypoint_test.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/utils_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ def test_entry_point_plugins_valid_groups():
118118
results = entry_point_plugins("console_scripts")
119119
match = False
120120
for result in results:
121-
if result.endswith("errbot/errbot.cli"):
121+
if "errbot" in result:
122122
match = True
123123
assert match
124+
125+
126+
def test_entry_point_paths_empty():
127+
groups = ["errbot.plugins", "errbot.backend_plugins"]
128+
for entry_point_group in groups:
129+
plugins = entry_point_plugins(entry_point_group)
130+
assert plugins == []

0 commit comments

Comments
 (0)