Skip to content

Commit

Permalink
Merge branch 'main' into improved_test_setup
Browse files Browse the repository at this point in the history
  • Loading branch information
sezanzeb committed Oct 16, 2024
2 parents 055047a + 4da1f7f commit 9e59630
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 33 deletions.
6 changes: 2 additions & 4 deletions inputremapper/configs/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import enum
from collections import namedtuple
from packaging import version
from typing import Optional, Callable, Tuple, TypeVar, Union, Any, Dict

import pkg_resources
from evdev.ecodes import (
EV_KEY,
EV_ABS,
Expand Down Expand Up @@ -83,9 +83,7 @@
# TODO: remove pydantic VERSION check as soon as we no longer support
# Ubuntu 20.04 and with it the ancient pydantic 1.2

needs_workaround = pkg_resources.parse_version(
str(VERSION)
) < pkg_resources.parse_version("1.7.1")
needs_workaround = version.parse(str(VERSION)) < version.parse("1.7.1")


EMPTY_MAPPING_NAME: str = _("Empty Mapping")
Expand Down
22 changes: 11 additions & 11 deletions inputremapper/configs/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import re
import shutil
from pathlib import Path
from packaging import version
from typing import Iterator, Tuple, Dict, List, Optional, TypedDict

import pkg_resources
from evdev.ecodes import (
EV_KEY,
EV_ABS,
Expand Down Expand Up @@ -76,29 +76,29 @@ def migrate():

v = Migrations.config_version()

if v < pkg_resources.parse_version("0.4.0"):
if v < version.parse("0.4.0"):
Migrations._config_suffix()
Migrations._preset_path()

if v < pkg_resources.parse_version("1.2.2"):
if v < version.parse("1.2.2"):
Migrations._mapping_keys()

if v < pkg_resources.parse_version("1.4.0"):
if v < version.parse("1.4.0"):
global_uinputs.prepare_all()
Migrations._add_target()

if v < pkg_resources.parse_version("1.4.1"):
if v < version.parse("1.4.1"):
Migrations._otherwise_to_else()

if v < pkg_resources.parse_version("1.5.0"):
if v < version.parse("1.5.0"):
Migrations._remove_logs()

if v < pkg_resources.parse_version("1.6.0-beta"):
if v < version.parse("1.6.0-beta"):
Migrations._convert_to_individual_mappings()

# add new migrations here

if v < pkg_resources.parse_version(VERSION):
if v < version.parse(VERSION):
Migrations._update_version()

@staticmethod
Expand Down Expand Up @@ -130,15 +130,15 @@ def config_version():
config_path = os.path.join(PathUtils.config_path(), "config.json")

if not os.path.exists(config_path):
return pkg_resources.parse_version("0.0.0")
return version.parse("0.0.0")

with open(config_path, "r") as file:
config = json.load(file)

if "version" in config.keys():
return pkg_resources.parse_version(config["version"])
return version.parse(config["version"])

return pkg_resources.parse_version("0.0.0")
return version.parse("0.0.0")

@staticmethod
def _config_suffix():
Expand Down
6 changes: 4 additions & 2 deletions inputremapper/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,11 @@ def run(self):
capabilities = device.capabilities(absinfo=False)

key_capa = capabilities.get(EV_KEY)
abs_capa = capabilities.get(EV_ABS)
rel_capa = capabilities.get(EV_REL)

if key_capa is None and device_type != DeviceType.GAMEPAD:
# skip devices that don't provide buttons that can be mapped
if key_capa is None and abs_capa is None and rel_capa is None:
# skip devices that don't provide buttons or axes that can be mapped
logger.debug('"%s" has no useful capabilities', device.name)
continue

Expand Down
4 changes: 2 additions & 2 deletions readme/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ as shown in the screenshots below.
<img src="usage_2.png"/>
</p>

In the text input field, type the key to which you would like to map this input.
In the "Output" textbox on the right, type the key to which you would like to map this input.
More information about the possible mappings can be found in
[examples.md](./examples.md) and [below](#key-names). You can also write your macro
into the text input field. If you hit enter, it will switch to a multiline-editor with
into the "Output" textbox. If you hit enter, it will switch to a multiline-editor with
line-numbers.

Changes are saved automatically. Press the "Apply" button to activate (inject) the
Expand Down
20 changes: 13 additions & 7 deletions tests/unit/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,8 @@ def test_skip_camera(self):
self.assertIsNotNone(groups.find(name="gamepad"))

def test_device_with_only_ev_abs(self):
# could be anything, a lot of devices have ABS_X capabilities,
# so it is not treated as gamepad joystick and since it also
# doesn't have key capabilities, there is nothing to map.
# As Input Mapper can now map axes to buttons,
# a single EV_ABS device is valid for mapping.
fixtures["/foo/bar"] = {
"name": "qux",
"phys": "abcd2",
Expand All @@ -193,12 +192,19 @@ def test_device_with_only_ev_abs(self):

groups.refresh()
self.assertIsNotNone(groups.find(name="gamepad"))
self.assertIsNone(groups.find(name="qux"))
self.assertIsNotNone(groups.find(name="qux"))

def test_device_with_no_capabilities(self):
fixtures["/foo/bar"] = {
"name": "nulcap",
"phys": "abcd3",
"info": evdev.DeviceInfo(1, 2, 3, 4),
"capabilities": {},
}

# verify this test even works at all
fixtures["/foo/bar"].capabilities[EV_KEY] = [KEY_A]
groups.refresh()
self.assertIsNotNone(groups.find(name="qux"))
self.assertIsNotNone(groups.find(name="gamepad"))
self.assertIsNone(groups.find(name="nulcap"))

def test_duplicate_device(self):
fixtures["/dev/input/event100"] = {
Expand Down
10 changes: 3 additions & 7 deletions tests/unit/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import os
import shutil
import unittest
from packaging import version

import pkg_resources
from evdev.ecodes import (
EV_KEY,
EV_ABS,
Expand Down Expand Up @@ -385,9 +385,7 @@ def test_add_version(self):
file.write("{}")

Migrations.migrate()
self.assertEqual(
pkg_resources.parse_version(VERSION), Migrations.config_version()
)
self.assertEqual(version.parse(VERSION), Migrations.config_version())

def test_update_version(self):
path = os.path.join(PathUtils.config_path(), "config.json")
Expand All @@ -396,9 +394,7 @@ def test_update_version(self):
json.dump({"version": "0.1.0"}, file)

Migrations.migrate()
self.assertEqual(
pkg_resources.parse_version(VERSION), Migrations.config_version()
)
self.assertEqual(version.parse(VERSION), Migrations.config_version())

def test_config_version(self):
path = os.path.join(PathUtils.config_path(), "config.json")
Expand Down

0 comments on commit 9e59630

Please sign in to comment.