Repository: pwr-Solaar/Solaar

Issue:
project now vendors hid-parser, blocks update
**Information**
<!-- Make sure that your issue is not one of the known issues in the Solaar documentation at https://pwr-solaar.github.io/Solaar/ -->
<!-- Do not bother opening an issue for a version older than 1.1.0.  Upgrade to the latest version and see if your issue persists. -->
<!-- If you not running the current version of Solaar, strongly consider upgrading to the newest version. -->
- Solaar version (`solaar --version` or `git describe --tags` if cloned from this repository): 1.1.6
- Distribution: Arch Linux
- Kernel version (ex. `uname -srmo`): n/a
- Output of `solaar show`: n/a

- Contents of `~/.config/solaar/config.yaml` (or `~/.config/solaar/config.json` if `~/.config/solaar/config.yaml` not present): n/a

- Errors or warrnings from Solaar: n/a
<!-- Under normal operation Solaar keeps a log of warning and error messages in ~/.tmp
while it is running as a file starting with 'Solaar'.
If this file is not available or does not have useful information you can
run Solaar as `solaar -dd`, after killing any running Solaar processes to
have Solaar log informational, warning, and error messages to stdout. -->


**Describe the bug**
Hi, I am packaging solaar for Arch Linux.
Distribution packaging relies on separation of concerns and separation of packages. The vendoring of hid-parser needs to be undone by all downstream distributions again, because it is available as a separate package and can be used by other Python packages as well (see https://github.com/pwr-Solaar/Solaar/pull/1783#issuecomment-1290174757).

Please make sure to rely on hid-parser as a normal dependency and remove the git submodule again as I will not update the package this way.

**To Reproduce**
Steps to reproduce the behavior:
1. Try to Package solaar as a Python package without vendoring
2. Each distribution starts to patch around in the code base to not have two versions of hid-parser in their repos

**Screenshots**
n/a

**Additional context**
Devendoring of readily available libraries poses an unnecessary workload on downstream distributions. In this case it seems not necessary at all to vendor hid-parser and the library could have been depended upon as a normal Python dependency (like [all the other dependencies this project has already](https://github.com/pwr-Solaar/Solaar/blob/9ce0fd7060a1d3b8e0ab4b3a70027ddc00c075db/setup.py#L63-L69)).


Discussion:
Is hid-parser already available on arch linux as a separate package?
See discussion in #1075.
> Is hid-parser already available on arch linux as a separate package?

It will be packaged as soon as at least one other package requires it.
But if hid-parser is not packaged how can Solaar use it as a dependency?  The other dependencies of Solaar are already packaged in distributions.

Resolving patch:
diff --git a/lib/hidapi/udev.py b/lib/hidapi/udev.py
--- a/lib/hidapi/udev.py
+++ b/lib/hidapi/udev.py
@@ -36,8 +36,6 @@
 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/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -67,8 +67,12 @@ def _data_files():
         '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/*'),
 )


Test patch: