1313from .util import load_config
1414from .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
2020def _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
0 commit comments