Skip to content

Commit 878e043

Browse files
Pierre-Luc Tessier Gagnéhardbyte
authored andcommitted
Simplifying the plugin interface
1 parent d64f87f commit 878e043

File tree

5 files changed

+14
-32
lines changed

5 files changed

+14
-32
lines changed

can/interface.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import importlib
55

66
from can.broadcastmanager import CyclicSendTaskABC, MultiRateCyclicSendTaskABC
7-
from can.plugin import get_pluginmanager
7+
from pkg_resources import iter_entry_points
88
from can.util import load_config
99

1010
# interface_name => (module, classname)
@@ -25,6 +25,12 @@
2525
}
2626

2727

28+
BACKENDS.update({
29+
interface.name: (interface.module_name, interface.attrs[0])
30+
for interface in iter_entry_points('python_can.interface')
31+
})
32+
33+
2834
class Bus(object):
2935
"""
3036
Instantiates a CAN Bus of the given `bustype`, falls back to reading a
@@ -59,12 +65,7 @@ def __new__(cls, other, channel=None, *args, **kwargs):
5965

6066
# Import the correct Bus backend
6167
try:
62-
interfaces_hook = get_pluginmanager().hook
63-
plugin = interfaces_hook.pythoncan_interface(interface=interface)
64-
if plugin:
65-
(module_name, class_name) = plugin[0]
66-
else:
67-
(module_name, class_name) = BACKENDS[interface]
68+
(module_name, class_name) = BACKENDS[interface]
6869
except KeyError:
6970
raise NotImplementedError("CAN interface '{}' not supported".format(interface))
7071

can/interfaces/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
"""
33
Interfaces contain low level implementations that interact with CAN hardware.
44
"""
5+
from pkg_resources import iter_entry_points
56

67
VALID_INTERFACES = set(['kvaser', 'serial', 'pcan', 'socketcan_native',
78
'socketcan_ctypes', 'socketcan', 'usb2can', 'ixxat',
89
'nican', 'iscan', 'vector', 'virtual', 'neovi',
910
'slcan'])
11+
12+
13+
VALID_INTERFACES.update(set([
14+
interface.name for interface in iter_entry_points('python_can.interface')
15+
]))

can/interfaces/hookspecs.py

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

can/plugin.py

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

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
# Tests can be run using `python setup.py test`
3030
test_suite="nose.collector",
3131
tests_require=['mock', 'nose', 'pyserial'],
32-
install_requires=['pluggy'],
3332
extras_require={
3433
'serial': ['pyserial'],
3534
'neovi': ['python-ics'],

0 commit comments

Comments
 (0)