19
19
# mikefsq, r2 2025
20
20
21
21
import usb .core # type: ignore[import-untyped]
22
- from typing import Optional , Union , List , TypedDict , cast , TYPE_CHECKING , Any
23
22
import logging
24
- from platform import system
25
23
import importlib .util
26
24
import os
25
+ from platform import system
26
+ from typing import Optional , Union , List , TypedDict , cast , TYPE_CHECKING , Any
27
27
28
28
if TYPE_CHECKING :
29
29
from artisanlib .aillio .aillio_r1 import AillioR1
@@ -101,9 +101,7 @@ def detect_device() -> Optional[DEVICE_VARIANT]:
101
101
# Fallback to pyusb backend
102
102
try :
103
103
_log .debug ('Trying fallback pyusb backend' )
104
- import usb .backend .libusb1 # type: ignore[import-untyped, unused-ignore]
105
- import usb .core
106
- import os
104
+ import usb .backend .libusb1 # type: ignore[import-untyped, unused-ignore] # pylint: disable=redefined-outer-name
107
105
108
106
# Look for libusb DLL in common locations
109
107
dll_paths = [
@@ -149,7 +147,6 @@ def detect_device() -> Optional[DEVICE_VARIANT]:
149
147
backend = None
150
148
if system ().startswith ('Linux' ):
151
149
# Try to find system libusb
152
- import os
153
150
for shared_libusb_path in [
154
151
'/usr/lib/x86_64-linux-gnu/libusb-1.0.so' ,
155
152
'/usr/lib/x86_64-linux-gnu/libusb-1.0.so.0' ,
@@ -164,7 +161,6 @@ def detect_device() -> Optional[DEVICE_VARIANT]:
164
161
break
165
162
166
163
# Try to find device with the backend
167
- import usb .core
168
164
for variant in AillioBase .DEVICE_VARIANTS :
169
165
device = usb .core .find (idVendor = variant ['vid' ], idProduct = variant ['pid' ], backend = backend )
170
166
if device is not None :
@@ -212,7 +208,7 @@ def create(debug: bool = False) -> 'Optional[Union[AillioR1,AillioR2]]':
212
208
except usb .core .NoBackendError :
213
209
_log .error ('No USB backend available. Please ensure libusb is installed.' )
214
210
return None
215
- except Exception as e :
211
+ except Exception as e : # pylint: disable=broad-except
216
212
_log .exception ('Unexpected error creating Aillio instance: %s' , str (e ))
217
213
return None
218
214
0 commit comments