Skip to content

Commit c7ba84a

Browse files
authored
Fix entry_points deprecation (#1233)
* Fix entry_points deprectaion * Format code with black * Undo change that shall be in a separate PR Co-authored-by: felixdivo <[email protected]>
1 parent 48f9c27 commit c7ba84a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

can/interfaces/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@
3232
try:
3333
from importlib.metadata import entry_points
3434

35-
entry = entry_points()
36-
if "can.interface" in entry:
37-
BACKENDS.update(
38-
{
39-
interface.name: tuple(interface.value.split(":"))
40-
for interface in entry["can.interface"]
41-
}
42-
)
35+
try:
36+
entries = entry_points(group="can.interface")
37+
except TypeError:
38+
# Fallback for Python <3.10
39+
# See https://docs.python.org/3/library/importlib.metadata.html#entry-points, "Compatibility Note"
40+
entries = entry_points().get("can.interface", [])
41+
42+
BACKENDS.update(
43+
{interface.name: tuple(interface.value.split(":")) for interface in entries}
44+
)
4345
except ImportError:
4446
from pkg_resources import iter_entry_points
4547

0 commit comments

Comments
 (0)