Skip to content

Commit ad4d46e

Browse files
karldinghardbyte
authored andcommitted
Format files using black formatter
1 parent 0b97098 commit ad4d46e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+4408
-2968
lines changed

can/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
__version__ = "3.2.0"
1010

11-
log = logging.getLogger('can')
11+
log = logging.getLogger("can")
1212

1313
rc = dict()
1414

@@ -38,9 +38,10 @@ class CanError(IOError):
3838
from . import interface
3939
from .interface import Bus, detect_available_configs
4040

41-
from .broadcastmanager import \
42-
CyclicSendTaskABC, \
43-
LimitedDurationCyclicSendTaskABC, \
44-
ModifiableCyclicTaskABC, \
45-
MultiRateCyclicSendTaskABC, \
46-
RestartableCyclicTaskABC
41+
from .broadcastmanager import (
42+
CyclicSendTaskABC,
43+
LimitedDurationCyclicSendTaskABC,
44+
ModifiableCyclicTaskABC,
45+
MultiRateCyclicSendTaskABC,
46+
RestartableCyclicTaskABC,
47+
)

can/broadcastmanager.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import threading
1313
import time
1414

15-
log = logging.getLogger('can.bcm')
15+
log = logging.getLogger("can.bcm")
1616

1717

1818
class CyclicTask:
@@ -47,7 +47,6 @@ def __init__(self, message, period):
4747

4848

4949
class LimitedDurationCyclicSendTaskABC(CyclicSendTaskABC):
50-
5150
def __init__(self, message, period, duration):
5251
"""Message send task with a defined duration and period.
5352
@@ -101,9 +100,9 @@ def __init__(self, channel, message, count, initial_period, subsequent_period):
101100
super().__init__(channel, message, subsequent_period)
102101

103102

104-
class ThreadBasedCyclicSendTask(ModifiableCyclicTaskABC,
105-
LimitedDurationCyclicSendTaskABC,
106-
RestartableCyclicTaskABC):
103+
class ThreadBasedCyclicSendTask(
104+
ModifiableCyclicTaskABC, LimitedDurationCyclicSendTaskABC, RestartableCyclicTaskABC
105+
):
107106
"""Fallback cyclic send task using thread."""
108107

109108
def __init__(self, bus, lock, message, period, duration=None):

can/bus.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BusABC(metaclass=ABCMeta):
3131
"""
3232

3333
#: a string describing the underlying bus and/or channel
34-
channel_info = 'unknown'
34+
channel_info = "unknown"
3535

3636
#: Log level for received messages
3737
RECV_LOGGING_LEVEL = 9
@@ -81,7 +81,7 @@ def recv(self, timeout=None):
8181

8282
# return it, if it matches
8383
if msg and (already_filtered or self._matches_filters(msg)):
84-
LOG.log(self.RECV_LOGGING_LEVEL, 'Received: %s', msg)
84+
LOG.log(self.RECV_LOGGING_LEVEL, "Received: %s", msg)
8585
return msg
8686

8787
# if not, and timeout is None, try indefinitely
@@ -213,6 +213,7 @@ def wrapped_stop_method(remove_task=True):
213213
except ValueError:
214214
pass
215215
original_stop_method()
216+
216217
task.stop = wrapped_stop_method
217218

218219
if store_task:
@@ -239,8 +240,12 @@ def _send_periodic_internal(self, msg, period, duration=None):
239240
"""
240241
if not hasattr(self, "_lock_send_periodic"):
241242
# Create a send lock for this bus, but not for buses which override this method
242-
self._lock_send_periodic = threading.Lock() # pylint: disable=attribute-defined-outside-init
243-
task = ThreadBasedCyclicSendTask(self, self._lock_send_periodic, msg, period, duration)
243+
self._lock_send_periodic = (
244+
threading.Lock()
245+
) # pylint: disable=attribute-defined-outside-init
246+
task = ThreadBasedCyclicSendTask(
247+
self, self._lock_send_periodic, msg, period, duration
248+
)
244249
return task
245250

246251
def stop_all_periodic_tasks(self, remove_tasks=True):
@@ -332,13 +337,12 @@ def _matches_filters(self, msg):
332337

333338
for _filter in self._filters:
334339
# check if this filter even applies to the message
335-
if 'extended' in _filter and \
336-
_filter['extended'] != msg.is_extended_id:
340+
if "extended" in _filter and _filter["extended"] != msg.is_extended_id:
337341
continue
338342

339343
# then check for the mask and id
340-
can_id = _filter['can_id']
341-
can_mask = _filter['can_mask']
344+
can_id = _filter["can_id"]
345+
can_mask = _filter["can_mask"]
342346

343347
# basically, we compute
344348
# `msg.arbitration_id & can_mask == can_id & can_mask`

can/ctypesutil.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import logging
99
import sys
1010

11-
log = logging.getLogger('can.ctypesutil')
11+
log = logging.getLogger("can.ctypesutil")
1212

13-
__all__ = ['CLibrary', 'HANDLE', 'PHANDLE', 'HRESULT']
13+
__all__ = ["CLibrary", "HANDLE", "PHANDLE", "HRESULT"]
1414

1515
try:
1616
_LibBase = ctypes.WinDLL
@@ -40,10 +40,16 @@ def map_symbol(self, func_name, restype=None, argtypes=(), errcheck=None):
4040
try:
4141
symbol = prototype((func_name, self))
4242
except AttributeError:
43-
raise ImportError("Could not map function '{}' from library {}".format(func_name, self._name))
43+
raise ImportError(
44+
"Could not map function '{}' from library {}".format(
45+
func_name, self._name
46+
)
47+
)
4448

4549
setattr(symbol, "_name", func_name)
46-
log.debug(f'Wrapped function "{func_name}", result type: {type(restype)}, error_check {errcheck}')
50+
log.debug(
51+
f'Wrapped function "{func_name}", result type: {type(restype)}, error_check {errcheck}'
52+
)
4753

4854
if errcheck:
4955
symbol.errcheck = errcheck
@@ -95,4 +101,5 @@ class HRESULT(ctypes.c_long):
95101
class HANDLE(ctypes.c_void_p):
96102
pass
97103

104+
98105
PHANDLE = ctypes.POINTER(HANDLE)

can/interface.py

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from .util import load_config
1414
from .interfaces import BACKENDS
1515

16-
log = logging.getLogger('can.interface')
17-
log_autodetect = log.getChild('detect_available_configs')
16+
log = logging.getLogger("can.interface")
17+
log_autodetect = log.getChild("detect_available_configs")
1818

1919

2020
def _get_class_for_interface(interface):
@@ -38,22 +38,25 @@ def _get_class_for_interface(interface):
3838
module = importlib.import_module(module_name)
3939
except Exception as e:
4040
raise ImportError(
41-
"Cannot import module {} for CAN interface '{}': {}".format(module_name, interface, e)
41+
"Cannot import module {} for CAN interface '{}': {}".format(
42+
module_name, interface, e
43+
)
4244
)
4345

4446
# Get the correct class
4547
try:
4648
bus_class = getattr(module, class_name)
4749
except Exception as e:
4850
raise ImportError(
49-
"Cannot import class {} from module {} for CAN interface '{}': {}"
50-
.format(class_name, module_name, interface, e)
51+
"Cannot import class {} from module {} for CAN interface '{}': {}".format(
52+
class_name, module_name, interface, e
53+
)
5154
)
5255

5356
return bus_class
5457

5558

56-
class Bus(BusABC): # pylint disable=abstract-method
59+
class Bus(BusABC): # pylint disable=abstract-method
5760
"""Bus wrapper with configuration loading.
5861
5962
Instantiates a CAN Bus of the given ``interface``, falls back to reading a
@@ -85,26 +88,26 @@ def __new__(cls, channel=None, *args, **kwargs):
8588

8689
# figure out the rest of the configuration; this might raise an error
8790
if channel is not None:
88-
kwargs['channel'] = channel
89-
if 'context' in kwargs:
90-
context = kwargs['context']
91-
del kwargs['context']
91+
kwargs["channel"] = channel
92+
if "context" in kwargs:
93+
context = kwargs["context"]
94+
del kwargs["context"]
9295
else:
9396
context = None
9497
kwargs = load_config(config=kwargs, context=context)
9598

9699
# resolve the bus class to use for that interface
97-
cls = _get_class_for_interface(kwargs['interface'])
100+
cls = _get_class_for_interface(kwargs["interface"])
98101

99102
# remove the 'interface' key so it doesn't get passed to the backend
100-
del kwargs['interface']
103+
del kwargs["interface"]
101104

102105
# make sure the bus can handle this config format
103-
if 'channel' not in kwargs:
106+
if "channel" not in kwargs:
104107
raise ValueError("'channel' argument missing")
105108
else:
106-
channel = kwargs['channel']
107-
del kwargs['channel']
109+
channel = kwargs["channel"]
110+
del kwargs["channel"]
108111

109112
if channel is None:
110113
# Use the default channel for the backend
@@ -137,7 +140,7 @@ def detect_available_configs(interfaces=None):
137140
if interfaces is None:
138141
interfaces = BACKENDS
139142
elif isinstance(interfaces, str):
140-
interfaces = (interfaces, )
143+
interfaces = (interfaces,)
141144
# else it is supposed to be an iterable of strings
142145

143146
result = []
@@ -146,21 +149,33 @@ def detect_available_configs(interfaces=None):
146149
try:
147150
bus_class = _get_class_for_interface(interface)
148151
except ImportError:
149-
log_autodetect.debug('interface "%s" can not be loaded for detection of available configurations', interface)
152+
log_autodetect.debug(
153+
'interface "%s" can not be loaded for detection of available configurations',
154+
interface,
155+
)
150156
continue
151157

152158
# get available channels
153159
try:
154-
available = list(bus_class._detect_available_configs()) # pylint: disable=protected-access
160+
available = list(
161+
bus_class._detect_available_configs()
162+
) # pylint: disable=protected-access
155163
except NotImplementedError:
156-
log_autodetect.debug('interface "%s" does not support detection of available configurations', interface)
164+
log_autodetect.debug(
165+
'interface "%s" does not support detection of available configurations',
166+
interface,
167+
)
157168
else:
158-
log_autodetect.debug('interface "%s" detected %i available configurations', interface, len(available))
169+
log_autodetect.debug(
170+
'interface "%s" detected %i available configurations',
171+
interface,
172+
len(available),
173+
)
159174

160175
# add the interface name to the configs if it is not already present
161176
for config in available:
162-
if 'interface' not in config:
163-
config['interface'] = interface
177+
if "interface" not in config:
178+
config["interface"] = interface
164179

165180
# append to result
166181
result += available

can/interfaces/__init__.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,29 @@
1010

1111
# interface_name => (module, classname)
1212
BACKENDS = {
13-
'kvaser': ('can.interfaces.kvaser', 'KvaserBus'),
14-
'socketcan': ('can.interfaces.socketcan', 'SocketcanBus'),
15-
'serial': ('can.interfaces.serial.serial_can','SerialBus'),
16-
'pcan': ('can.interfaces.pcan', 'PcanBus'),
17-
'usb2can': ('can.interfaces.usb2can', 'Usb2canBus'),
18-
'ixxat': ('can.interfaces.ixxat', 'IXXATBus'),
19-
'nican': ('can.interfaces.nican', 'NicanBus'),
20-
'iscan': ('can.interfaces.iscan', 'IscanBus'),
21-
'virtual': ('can.interfaces.virtual', 'VirtualBus'),
22-
'neovi': ('can.interfaces.ics_neovi', 'NeoViBus'),
23-
'vector': ('can.interfaces.vector', 'VectorBus'),
24-
'slcan': ('can.interfaces.slcan', 'slcanBus'),
25-
'canalystii': ('can.interfaces.canalystii', 'CANalystIIBus'),
26-
'systec': ('can.interfaces.systec', 'UcanBus')
13+
"kvaser": ("can.interfaces.kvaser", "KvaserBus"),
14+
"socketcan": ("can.interfaces.socketcan", "SocketcanBus"),
15+
"serial": ("can.interfaces.serial.serial_can", "SerialBus"),
16+
"pcan": ("can.interfaces.pcan", "PcanBus"),
17+
"usb2can": ("can.interfaces.usb2can", "Usb2canBus"),
18+
"ixxat": ("can.interfaces.ixxat", "IXXATBus"),
19+
"nican": ("can.interfaces.nican", "NicanBus"),
20+
"iscan": ("can.interfaces.iscan", "IscanBus"),
21+
"virtual": ("can.interfaces.virtual", "VirtualBus"),
22+
"neovi": ("can.interfaces.ics_neovi", "NeoViBus"),
23+
"vector": ("can.interfaces.vector", "VectorBus"),
24+
"slcan": ("can.interfaces.slcan", "slcanBus"),
25+
"canalystii": ("can.interfaces.canalystii", "CANalystIIBus"),
26+
"systec": ("can.interfaces.systec", "UcanBus"),
2727
}
2828

29-
BACKENDS.update({
30-
interface.name: (interface.module_name, interface.attrs[0])
31-
for interface in iter_entry_points('can.interface')
32-
})
29+
BACKENDS.update(
30+
{
31+
interface.name: (interface.module_name, interface.attrs[0])
32+
for interface in iter_entry_points("can.interface")
33+
}
34+
)
3335

34-
VALID_INTERFACES = frozenset(list(BACKENDS.keys()) + ['socketcan_native', 'socketcan_ctypes'])
36+
VALID_INTERFACES = frozenset(
37+
list(BACKENDS.keys()) + ["socketcan_native", "socketcan_ctypes"]
38+
)

0 commit comments

Comments
 (0)