Skip to content

Commit bef51d0

Browse files
kkerooklemen1999
andauthored
Compatibility fix for importlib package. (#296)
Co-authored-by: klemen1999 <[email protected]>
1 parent 6b2787b commit bef51d0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

luxonis_ml/data/__init__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,32 @@
2222

2323
def load_dataset_plugins() -> None: # pragma: no cover
2424
"""Registers any external dataset BaseDataset class plugins."""
25-
for entry_point in entry_points().get("dataset_plugins", []):
25+
for entry_point in _get_entry_points_subset("dataset_plugins"):
2626
plugin_class = entry_point.load()
2727
DATASETS_REGISTRY.register(module=plugin_class)
2828

2929

3030
def load_loader_plugins() -> None: # pragma: no cover
3131
"""Registers any external dataset BaseLoader class plugins."""
32-
for entry_point in entry_points().get("loader_plugins", []):
32+
for entry_point in _get_entry_points_subset("loader_plugins"):
3333
plugin_class = entry_point.load()
3434
DATASETS_REGISTRY.register(module=plugin_class)
3535

3636

37+
def _get_entry_points_subset(key: str) -> list:
38+
"""Returns subset of selected entry points.
39+
40+
Safe function for older (py3.8) and newer py versions
41+
"""
42+
entry_points_obj = entry_points()
43+
if isinstance(entry_points_obj, dict):
44+
# py3.8 specific
45+
selected_entry_points = entry_points_obj.get(key, [])
46+
else:
47+
selected_entry_points = entry_points_obj.select(group=key)
48+
return selected_entry_points
49+
50+
3751
load_dataset_plugins()
3852
load_loader_plugins()
3953

0 commit comments

Comments
 (0)