Skip to content

Commit

Permalink
cli: move imports in __init__.py to top of file
Browse files Browse the repository at this point in the history
  • Loading branch information
pfps committed Feb 11, 2024
1 parent 2a1441c commit ddbba3a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/solaar/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import logging
import sys as _sys

from importlib import import_module
from traceback import extract_tb, format_exc

from logitech_receiver import Device, Receiver
from logitech_receiver.base import receivers, receivers_and_devices
from solaar import NAME

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -104,8 +109,6 @@ def _create_parser():


def _receivers(dev_path=None):
from logitech_receiver import Receiver
from logitech_receiver.base import receivers
for dev_info in receivers():
if dev_path is not None and dev_path != dev_info.path:
continue
Expand All @@ -121,8 +124,6 @@ def _receivers(dev_path=None):


def _receivers_and_devices(dev_path=None):
from logitech_receiver import Device, Receiver
from logitech_receiver.base import receivers_and_devices
for dev_info in receivers_and_devices():
if dev_path is not None and dev_path != dev_info.path:
continue
Expand Down Expand Up @@ -212,13 +213,10 @@ def run(cli_args=None, hidraw_path=None):
raise Exception(
'No supported device found. Use "lsusb" and "bluetoothctl devices Connected" to list connected devices.'
)
from importlib import import_module
m = import_module('.' + action, package=__name__)
m.run(c, args, _find_receiver, _find_device)
except AssertionError:
from traceback import extract_tb
tb_last = extract_tb(_sys.exc_info()[2])[-1]
_sys.exit('%s: assertion failed: %s line %d' % (NAME.lower(), tb_last[0], tb_last[1]))
except Exception:
from traceback import format_exc
_sys.exit('%s: error: %s' % (NAME.lower(), format_exc()))

0 comments on commit ddbba3a

Please sign in to comment.