Skip to content

Commit

Permalink
Fix for UI_FF constants missing from generated ecodes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gvalkov committed Feb 21, 2025
1 parent 7916a7b commit 73f8e15
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Run pytest tests
# pip install -e . builds _ecodes and such into the evdev directory
# sudo required to write to uinputs
run: |
sudo python -m pip install pytest setuptools
Expand Down
17 changes: 15 additions & 2 deletions src/evdev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
# Gather everything into a single, convenient namespace.
# --------------------------------------------------------------------------

from . import ecodes as ecodes, ff as ff
# The superfluous "import name as name" syntax is here to satisfy mypy's attrs-defined rule.
# Alternarantively all exported objects can be listed in __all__.

from . import (
ecodes as ecodes,
ff as ff,
)

from .device import (
AbsInfo as AbsInfo,
DeviceInfo as DeviceInfo,
EvdevError as EvdevError,
InputDevice as InputDevice,
)

from .events import (
AbsEvent as AbsEvent,
InputEvent as InputEvent,
Expand All @@ -17,7 +25,12 @@
SynEvent as SynEvent,
event_factory as event_factory,
)
from .uinput import UInput as UInput, UInputError as UInputError

from .uinput import (
UInput as UInput,
UInputError as UInputError,
)

from .util import (
categorize as categorize,
list_devices as list_devices,
Expand Down
2 changes: 1 addition & 1 deletion src/evdev/ecodes_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#: Mapping of names to values.
ecodes = {}

prefixes = "KEY ABS REL SW MSC LED BTN REP SND ID EV BUS SYN FF_STATUS FF INPUT_PROP".split()
prefixes = "KEY ABS REL SW MSC LED BTN REP SND ID EV BUS SYN FF_STATUS FF INPUT_PROP UI_FF".split()
prev_prefix = ""
g = globals()

Expand Down
3 changes: 2 additions & 1 deletion src/evdev/genecodes_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
("BUS", "Dict[int, Union[str, Tuple[str]]]", None),
("SYN", "Dict[int, Union[str, Tuple[str]]]", None),
("FF", "Dict[int, Union[str, Tuple[str]]]", None),
("UI_FF", "Dict[int, Union[str, Tuple[str]]]", None),
("FF_STATUS", "Dict[int, Union[str, Tuple[str]]]", None),
("INPUT_PROP", "Dict[int, Union[str, Tuple[str]]]", None)
]
Expand All @@ -50,4 +51,4 @@

print(f"{key}: {annotation} = ", end="")
pprint(getattr(ecodes, key))
print()
print()
16 changes: 13 additions & 3 deletions tests/test_ecodes.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# encoding: utf-8

from evdev import ecodes
from evdev import ecodes_runtime


prefixes = "KEY ABS REL SW MSC LED BTN REP SND ID EV BUS SYN FF_STATUS FF"
prefixes = "KEY ABS REL SW MSC LED BTN REP SND ID EV BUS SYN FF_STATUS FF UI_FF"


def to_tuples(val):
Expand All @@ -29,3 +28,14 @@ def test_overlap():
vals_ff = set(to_tuples(ecodes.FF.values()))
vals_ff_status = set(to_tuples(ecodes.FF_STATUS.values()))
assert bool(vals_ff & vals_ff_status) is False


def test_generated():
e_run = vars(ecodes_runtime)
e_gen = vars(ecodes)

def keys(v):
res = {k for k in v.keys() if not k.startswith("_") and not k[1].islower()}
return res

assert keys(e_run) == keys(e_gen)

0 comments on commit 73f8e15

Please sign in to comment.