Skip to content

Commit

Permalink
Merge branch 'master' into test_device_1097
Browse files Browse the repository at this point in the history
  • Loading branch information
pfps authored Feb 20, 2024
2 parents db87415 + fa94944 commit e031a5d
Show file tree
Hide file tree
Showing 38 changed files with 553 additions and 481 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4.3.0
- name: Set up Python
uses: actions/setup-python@v5

- name: Run pre-commit
uses: pre-commit/action@v3.0.0
30 changes: 14 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,58 @@ name: tests
on: [push, pull_request]

jobs:
build:
ubuntu-tests:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.7, 3.12]

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4.3.0
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Ubuntu dependencies
run: |
sudo apt update
sudo apt install libdbus-1-dev libglib2.0-dev
make install_apt
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[test]
make install_pip PIP_ARGS='.["test"]'
- name: Run tests on Ubuntu
run: |
pytest
make test
macos-build:
macos-tests:
runs-on: macos-latest

strategy:
matrix:
python-version: [3.7, 3.12]

steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4.3.0
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Set up macOS dependencies
run: |
brew install hidapi gtk+3 pygobject3
make install_brew
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install ."[test]"
make install_pip PIP_ARGS='.["test"]'
- name: Run tests on macOS
run: |
pytest
make test
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 1.1.11rc4
# 1.1.11

* Rename light icons and install them in correct place
* Setup macOS tests using GitHub action (#2284)
Expand Down
38 changes: 35 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,51 @@ UDEV_RULES_SOURCE := rules.d/$(UDEV_RULE_FILE)
UDEV_RULES_SOURCE_UINPUT := rules.d-uinput/$(UDEV_RULE_FILE)
UDEV_RULES_DEST := /etc/udev/rules.d/

.PHONY: install_udev install_udev_uinput uninstall_udev
PIP_ARGS ?= .

.PHONY: install_ubuntu install_macos
.PHONY: install_apt install_brew install_pip
.PHONY: install_udev install_udev_uinput reload_udev uninstall_udev
.PHONY: test

install_ubuntu: install_apt install_udev_uinput install_pip

install_macos: install_brew install_pip

install_apt:
@echo "Installing Solaar dependencies via apt"
sudo apt update
sudo apt install libdbus-1-dev libglib2.0-dev

install_brew:
@echo "Installing Solaar dependencies via brew"
brew update
brew install hidapi gtk+3 pygobject3

install_pip:
@echo "Installing Solaar dependencies via pip"
python -m pip install --upgrade pip
pip install $(PIP_ARGS)

install_udev:
@echo "Copying Solaar udev rule to $(UDEV_RULES_DEST)"
sudo cp $(UDEV_RULES_SOURCE) $(UDEV_RULES_DEST)
sudo udevadm control --reload-rules
make reload_udev

install_udev_uinput:
@echo "Copying Solaar udev rule (uinput) to $(UDEV_RULES_DEST)"
sudo cp $(UDEV_RULES_SOURCE_UINPUT) $(UDEV_RULES_DEST)
make reload_udev

reload_udev:
@echo "Reloading udev rules"
sudo udevadm control --reload-rules

uninstall_udev:
@echo "Removing Solaar udev rules from $(UDEV_RULES_DEST)"
sudo rm -f $(UDEV_RULES_DEST)/$(UDEV_RULE_FILE)
sudo udevadm control --reload-rules
make reload_udev

test:
@echo "Running Solaar tests"
pytest --cov=lib/ tests/
2 changes: 1 addition & 1 deletion Release_Notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Notes on Major Changes in Releases

## Version 1.1.11rc2
## Version 1.1.11

* Solaar can dump device profiles in YAMLfor devices that support profiles and load profiles back from an edited file. See [the capabilities page](https://pwr-solaar.github.io/Solaar/capabilities) for more information.

Expand Down
16 changes: 10 additions & 6 deletions lib/hidapi/hidapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
from threading import Thread
from time import sleep

import gi

gi.require_version('Gdk', '3.0')
from gi.repository import GLib # NOQA: E402

logger = logging.getLogger(__name__)

native_implementation = 'hidapi'
Expand Down Expand Up @@ -257,7 +262,7 @@ def _match(action, device, filterfn):
device['hidpp_long'] = True
except HIDError as e: # noqa: F841
if logger.isEnabledFor(logging.INFO):
logger.info(f"Error opening device {device['path']} ({bus_id}/{vid:04X}/{pid:04X}) for hidpp check: {e}")
logger.info(f"Error opening device {device['path']} ({bus_id}/{vid:04X}/{pid:04X}) for hidpp check: {e}") # noqa
finally:
if device_handle:
close(device_handle)
Expand All @@ -279,8 +284,8 @@ def _match(action, device, filterfn):
d_info = DeviceInfo(
path=device['path'].decode(),
bus_id=bus_id,
vendor_id=f'{vid:04X}',
product_id=f'{pid:04X}',
vendor_id=f'{vid:04X}', # noqa
product_id=f'{pid:04X}', # noqa
interface=None,
driver=None,
manufacturer=device['manufacturer_string'],
Expand All @@ -297,8 +302,8 @@ def _match(action, device, filterfn):
d_info = DeviceInfo(
path=device['path'].decode(),
bus_id=None,
vendor_id=f'{vid:04X}',
product_id=f'{pid:04X}',
vendor_id=f'{vid:04X}', # noqa
product_id=f'{pid:04X}', # noqa
interface=None,
driver=None,
manufacturer=None,
Expand All @@ -323,7 +328,6 @@ def find_paired_node_wpid(receiver_path, index):


def monitor_glib(callback, filterfn):
from gi.repository import GLib

def device_callback(action, device):
# print(f"device_callback({action}): {device}")
Expand Down
9 changes: 4 additions & 5 deletions lib/hidapi/hidconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import argparse
import os
import os.path
import readline
import sys
import time

from binascii import hexlify, unhexlify
from select import select as _select
from threading import Lock
from threading import Lock, Thread

import hidapi as _hid

Expand Down Expand Up @@ -176,7 +179,6 @@ def matchfn(bid, vid, pid, _a, _b):


def _parse_arguments():
import argparse
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--history', help='history file (default ~/.hidconsole-history)')
arg_parser.add_argument('--hidpp', action='store_true', help='ensure input data is a valid HID++ request')
Expand All @@ -196,9 +198,7 @@ def main():
if interactive:
print('.. Press ^C/^D to exit, or type hex bytes to write to the device.')

import readline
if args.history is None:
import os.path
args.history = os.path.join(os.path.expanduser('~'), '.hidconsole-history')
try:
readline.read_history_file(args.history)
Expand All @@ -207,7 +207,6 @@ def main():
pass

try:
from threading import Thread
t = Thread(target=_continuous_read, args=(handle, ))
t.daemon = True
t.start()
Expand Down
19 changes: 13 additions & 6 deletions lib/hidapi/udev.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@
from time import sleep
from time import time as _timestamp

import gi

from hid_parser import ReportDescriptor as _ReportDescriptor
from pyudev import Context as _Context
from pyudev import Device as _Device
from pyudev import DeviceNotFoundError
from pyudev import Devices as _Devices
from pyudev import Monitor as _Monitor

gi.require_version('Gdk', '3.0')
from gi.repository import GLib # NOQA: E402

logger = logging.getLogger(__name__)

native_implementation = 'udev'
Expand Down Expand Up @@ -93,6 +99,8 @@ def exit():
# It is given the bus id, vendor id, and product id and returns a dictionary
# with the required hid_driver and usb_interface and whether this is a receiver or device.
def _match(action, device, filterfn):
if logger.isEnabledFor(logging.DEBUG):
logger.debug(f'Dbus event {action} {device}')
hid_device = device.find_parent('hid')
if not hid_device: # only HID devices are of interest to Solaar
return
Expand All @@ -105,9 +113,6 @@ def _match(action, device, filterfn):
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:
Expand All @@ -122,7 +127,7 @@ def _match(action, device, filterfn):
return
except Exception as e: # if can't process report descriptor fall back to old scheme
hidpp_short = hidpp_long = None
logger.warning(
logger.info(
'Report Descriptor not processed for DEVICE %s BID %s VID %s PID %s: %s', device.device_node, bid, vid, pid, e
)

Expand Down Expand Up @@ -236,8 +241,6 @@ def find_paired_node_wpid(receiver_path, index):


def monitor_glib(callback, filterfn):
from gi.repository import GLib

c = _Context()

# already existing devices
Expand Down Expand Up @@ -280,6 +283,8 @@ def _process_udev_event(monitor, condition, cb, filterfn):
GLib.io_add_watch(m, GLib.IO_IN, _process_udev_event, callback, filterfn)
# print ("did io_add_watch")

if logger.isEnabledFor(logging.DEBUG):
logger.debug('Starting dbus monitoring')
m.start()


Expand All @@ -292,6 +297,8 @@ def enumerate(filterfn):
:returns: a list of matching ``DeviceInfo`` tuples.
"""

if logger.isEnabledFor(logging.DEBUG):
logger.debug('Starting dbus enumeration')
for dev in _Context().list_devices(subsystem='hidraw'):
dev_info = _match('add', dev, filterfn)
if dev_info:
Expand Down
4 changes: 0 additions & 4 deletions lib/logitech_receiver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@

import logging

from . import listener, status # noqa: F401
from .common import strhex # noqa: F401
from .device import Device # noqa: F401
from .receiver import Receiver # noqa: F401

logger = logging.getLogger(__name__)
logger.setLevel(logging.root.level)
Expand Down
Loading

0 comments on commit e031a5d

Please sign in to comment.