diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 46d03bda..b6c603d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: hooks: - id: yapf - repo: https://github.com/pre-commit/mirrors-isort - rev: v4.3.21 + rev: v5.10.1 hooks: - id: isort - repo: https://github.com/PyCQA/flake8 diff --git a/bin/solaar b/bin/solaar index 9b589ec2..1ed01d81 100755 --- a/bin/solaar +++ b/bin/solaar @@ -21,8 +21,8 @@ def init_paths(): """Make the app work in the source tree.""" - import sys import os.path as _path + import sys # Python 2 need conversion from utf-8 filenames # Python 3 might have problems converting back to UTF-8 in case of Unicode surrogates diff --git a/lib/hidapi/udev.py b/lib/hidapi/udev.py index ed6b235e..89dd67db 100644 --- a/lib/hidapi/udev.py +++ b/lib/hidapi/udev.py @@ -107,6 +107,7 @@ def _match(action, device, filterfn): try: # if report descriptor does not indicate HID++ capabilities then this device is not of interest to Solaar from hid_parser import ReportDescriptor as _ReportDescriptor + # from hid_parser import Usage as _Usage hidpp_short = hidpp_long = False devfile = '/sys' + hid_device.get('DEVPATH') + '/report_descriptor' diff --git a/lib/solaar/cli/__init__.py b/lib/solaar/cli/__init__.py index ac441907..788b5adf 100644 --- a/lib/solaar/cli/__init__.py +++ b/lib/solaar/cli/__init__.py @@ -115,8 +115,7 @@ def _receivers(dev_path=None): def _receivers_and_devices(dev_path=None): - from logitech_receiver import Device - from logitech_receiver import Receiver + 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: diff --git a/lib/solaar/gtk.py b/lib/solaar/gtk.py index 24acd6ec..54537e3c 100755 --- a/lib/solaar/gtk.py +++ b/lib/solaar/gtk.py @@ -123,9 +123,10 @@ def _parse_arguments(): # On first SIGINT, dump threads to stderr; on second, exit def _handlesigint(signal, stack): + import faulthandler import signal import sys - import faulthandler + signal.signal(signal.SIGINT, signal.SIG_DFL) if _log.isEnabledFor(_INFO): @@ -160,8 +161,9 @@ def main(): _log.warning('Solaar udev file not found in expected location') _log.warning('See https://pwr-solaar.github.io/Solaar/installation for more information') try: - import solaar.ui as ui import solaar.listener as listener + import solaar.ui as ui + listener.setup_scanner(ui.status_changed, ui.error_dialog) import solaar.upower as _upower @@ -177,6 +179,7 @@ def main(): ui.run_loop(listener.start_all, listener.stop_all, args.window != 'only', args.window != 'hide') except Exception: import sys + from traceback import format_exc sys.exit('%s: error: %s' % (NAME.lower(), format_exc())) diff --git a/lib/solaar/i18n.py b/lib/solaar/i18n.py index cf30f6fd..7eddb7ef 100644 --- a/lib/solaar/i18n.py +++ b/lib/solaar/i18n.py @@ -28,7 +28,6 @@ from solaar import NAME as _NAME def _find_locale_path(lc_domain): import os.path as _path - import sys as _sys prefix_share = _path.normpath(_path.join(_path.realpath(_sys.path[0]), '..')) src_share = _path.normpath(_path.join(_path.realpath(_sys.path[0]), '..', 'share')) diff --git a/lib/solaar/listener.py b/lib/solaar/listener.py index 56e4eb91..d0ba5701 100644 --- a/lib/solaar/listener.py +++ b/lib/solaar/listener.py @@ -397,8 +397,8 @@ def _process_receiver_event(action, device_info): # (It would be easier to use pylibacl but adding the pylibacl dependencies # for this special case is not good.) try: - import subprocess import re + import subprocess output = subprocess.check_output(['/usr/bin/getfacl', '-p', device_info.path]) if not re.search(b'user:.+:', output): _error_callback('permissions', device_info.path) diff --git a/lib/solaar/ui/icons.py b/lib/solaar/ui/icons.py index d6dc03b8..537b2fed 100644 --- a/lib/solaar/ui/icons.py +++ b/lib/solaar/ui/icons.py @@ -47,9 +47,9 @@ TRAY_ATTENTION = 'solaar-attention' def _look_for_application_icons(): import os.path as _path - from os import environ as _environ - import sys as _sys + + from os import environ as _environ if _log.isEnabledFor(_DEBUG): _log.debug('sys.path[0] = %s', _sys.path[0]) prefix_share = _path.normpath(_path.join(_path.realpath(_sys.path[0]), '..')) diff --git a/lib/solaar/ui/notify.py b/lib/solaar/ui/notify.py index 6d4bfcf7..db3e7497 100644 --- a/lib/solaar/ui/notify.py +++ b/lib/solaar/ui/notify.py @@ -28,7 +28,7 @@ try: import gi gi.require_version('Notify', '0.7') # this import is allowed to fail, in which case the entire feature is unavailable - from gi.repository import Notify, GLib + from gi.repository import GLib, Notify # assumed to be working since the import succeeded available = True @@ -37,11 +37,13 @@ except (ValueError, ImportError): available = False if available: - from logging import getLogger, INFO as _INFO + from logging import INFO as _INFO + from logging import getLogger _log = getLogger(__name__) del getLogger from solaar import NAME + from . import icons as _icons # cache references to shown notifications here, so if another status comes diff --git a/tools/hidconsole b/tools/hidconsole index 7d494b01..d270aa27 100755 --- a/tools/hidconsole +++ b/tools/hidconsole @@ -7,8 +7,8 @@ from __future__ import absolute_import def init_paths(): """Make the app work in the source tree.""" - import sys import os.path as _path + import sys src_lib = _path.normpath(_path.join(_path.realpath(sys.path[0]), '..', 'lib')) init_py = _path.join(src_lib, 'hidapi', '__init__.py')