From 8d0795af531869ff0a2cb64841dbeeb0e5b236fe Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Tue, 25 Oct 2022 09:59:50 -0400 Subject: [PATCH] solaar: make hid-parser an optional dependency --- .gitmodules | 3 --- docs/installation.md | 8 ++++++-- lib/hid_parser | 1 - lib/hidapi/udev.py | 10 +++++----- python-hid-parser | 1 - setup.py | 6 +++++- 6 files changed, 16 insertions(+), 13 deletions(-) delete mode 120000 lib/hid_parser delete mode 160000 python-hid-parser diff --git a/.gitmodules b/.gitmodules index 24146f48..e69de29b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "python-hid-parser"] - path = python-hid-parser - url = https://github.com/usb-tools/python-hid-parser diff --git a/docs/installation.md b/docs/installation.md index f9f19269..ca5f7c55 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -7,8 +7,7 @@ layout: page ## Downloading -Clone Solaar from GitHub by `git clone --recurse-submodules https://github.com/pwr-Solaar/Solaar.git`. -Make sure that the submodule python-hid-parser was cloned, i.e., the directory `python-hid-parser` has content. +Clone Solaar from GitHub by `git clone https://github.com/pwr-Solaar/Solaar.git`. ## Requirements for Solaar @@ -33,6 +32,11 @@ in Fedora you need `gtk3` and `python3-gobject`. You may have to install `gcc` and the Python development package (`python3-dev` or `python3-devel`, depending on your distribution). +If the `hid_parser` Python package is available, Solaar parses HID report descriptors +and can control more HID++ devices that do not use a receiver. +This package may not be available in some distributions but can be installed using pip +via `pip install --user hid-parser`. + If you are running a version of Python different from the system version, you may need to use pip to install projects that provide the above Python packages. diff --git a/lib/hid_parser b/lib/hid_parser deleted file mode 120000 index b3fe592c..00000000 --- a/lib/hid_parser +++ /dev/null @@ -1 +0,0 @@ -../python-hid-parser/hid_parser \ No newline at end of file diff --git a/lib/hidapi/udev.py b/lib/hidapi/udev.py index 1a5ee83d..c20b1562 100644 --- a/lib/hidapi/udev.py +++ b/lib/hidapi/udev.py @@ -36,8 +36,6 @@ from select import select as _select from time import sleep from time import time as _timestamp -from hid_parser import ReportDescriptor as _ReportDescriptor -from hid_parser import Usage as _Usage from pyudev import Context as _Context from pyudev import Device as _Device from pyudev import DeviceNotFoundError @@ -103,8 +101,13 @@ def _match(action, device, filterfn): if not hid_id: return # there are reports that sometimes the id isn't set up right so be defensive bid, vid, pid = hid_id.split(':') + hid_hid_device = hid_device.find_parent('hid') + if hid_hid_device: + return # these are devices connected through a receiver so don't pick them up here 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' with fileopen(devfile, 'rb') as fd: @@ -122,9 +125,6 @@ def _match(action, device, filterfn): except Exception as e: # if can't process report descriptor fall back to old scheme hidpp_short = hidpp_long = None _log.warn('Report Descriptor not processed for BID %s VID %s PID %s: %s', bid, vid, pid, e) - hid_hid_device = hid_device.find_parent('hid') - if hid_hid_device: - return # these are devices connected through a receiver so don't pick them up here filter = filterfn(int(bid, 16), int(vid, 16), int(pid, 16), hidpp_short, hidpp_long) if not filter: diff --git a/python-hid-parser b/python-hid-parser deleted file mode 160000 index 4b7944f4..00000000 --- a/python-hid-parser +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4b7944f4999e152c678cd7fa76278b7e2535c3ff diff --git a/setup.py b/setup.py index 7fbb9453..96f2e32d 100755 --- a/setup.py +++ b/setup.py @@ -67,8 +67,12 @@ For instructions on installing Solaar see https://pwr-solaar.github.io/Solaar/in 'python-xlib (>= 0.27)', 'psutil (>= 5.4.3)', ], + extras_require={ + 'report-descriptor': ['hid-parser'], + 'desktop-notifications': ['Notify (>= 0.7)'], + }, package_dir={'': 'lib'}, - packages=['keysyms', 'hidapi', 'hid_parser', 'logitech_receiver', 'solaar', 'solaar.ui', 'solaar.cli'], + packages=['keysyms', 'hidapi', 'logitech_receiver', 'solaar', 'solaar.ui', 'solaar.cli'], data_files=list(_data_files()), scripts=_glob('bin/*'), )