Skip to content

Speed up imports by removing pkg_resources #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 18, 2021
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions can/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
Interfaces contain low level implementations that interact with CAN hardware.
"""

import warnings
from pkg_resources import iter_entry_points


# interface_name => (module, classname)
BACKENDS = {
"kvaser": ("can.interfaces.kvaser", "KvaserBus"),
Expand All @@ -31,11 +27,14 @@
"neousys": ("can.interfaces.neousys", "NeousysBus"),
}

BACKENDS.update(
{
interface.name: (interface.module_name, interface.attrs[0])
for interface in iter_entry_points("can.interface")
}
)
try:
from importlib.metadata import entry_points
entry = entry_points()
if 'can.interface' in entry:
BACKENDS.update({interface.name: tuple(interface.value.split(':')) for interface in entry['can.interface']})
except ImportError:
from pkg_resources import iter_entry_points
entry = iter_entry_points("can.interface")
BACKENDS.update({interface.name: (interface.module_name, interface.attrs[0]) for interface in entry})

VALID_INTERFACES = frozenset(list(BACKENDS.keys()))