From bcef0b627653e40a90467fab874a6770831953e4 Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Thu, 16 Jan 2025 18:52:59 +0100 Subject: [PATCH 01/18] Remove EOL python 3.7 from the ci --- .github/workflows/install.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/install.yaml b/.github/workflows/install.yaml index 7d965b2..65e2e2f 100644 --- a/.github/workflows/install.yaml +++ b/.github/workflows/install.yaml @@ -11,7 +11,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] include: - os: ubuntu-latest python-version: "3.7" From e5eab3e64e1e1cfe5790d905ce4b78a5c6d000f0 Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Thu, 16 Jan 2025 18:54:08 +0100 Subject: [PATCH 02/18] I wonder what that is for --- .github/workflows/install.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/install.yaml b/.github/workflows/install.yaml index 65e2e2f..f959de2 100644 --- a/.github/workflows/install.yaml +++ b/.github/workflows/install.yaml @@ -14,7 +14,7 @@ jobs: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] include: - os: ubuntu-latest - python-version: "3.7" + python-version: "3.8" steps: - uses: actions/checkout@v4 From 97c65daf3c812d46176d426baf1a795e3ac3f273 Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 05:29:40 +0100 Subject: [PATCH 03/18] Add pylint -E, fix some pylint errors --- .github/workflows/lint.yml | 22 ++++++++++++++++++++++ evdev/ecodes.py | 1 + evdev/eventio.py | 2 ++ evdev/events.py | 24 ++++++++++++------------ evdev/uinput.py | 2 +- 5 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..fda6f9d --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,22 @@ +name: Lint + +on: + - push + - pull_request + +jobs: + black: + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: ["3.12"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Check for pylint errors + run: pylint --disable=no-member -E evdev diff --git a/evdev/ecodes.py b/evdev/ecodes.py index 3562368..759cfe7 100644 --- a/evdev/ecodes.py +++ b/evdev/ecodes.py @@ -1,3 +1,4 @@ +# pylint: disable=undefined-variable """ This modules exposes the integer constants defined in ``linux/input.h`` and ``linux/input-event-codes.h``. diff --git a/evdev/eventio.py b/evdev/eventio.py index 415e2e8..3335500 100644 --- a/evdev/eventio.py +++ b/evdev/eventio.py @@ -72,6 +72,7 @@ def read(self): for event in events: yield InputEvent(*event) + # pylint: disable=no-self-argument def need_write(func): """ Decorator that raises :class:`EvdevError` if there is no write access to the @@ -82,6 +83,7 @@ def need_write(func): def wrapper(*args): fd = args[0].fd if fcntl.fcntl(fd, fcntl.F_GETFL) & os.O_RDWR: + # pylint: disable=not-callable return func(*args) msg = 'no write access to device "%s"' % args[0].path raise EvdevError(msg) diff --git a/evdev/events.py b/evdev/events.py index 104b563..97f570d 100644 --- a/evdev/events.py +++ b/evdev/events.py @@ -65,13 +65,13 @@ def timestamp(self): """Return event timestamp as a float.""" return self.sec + (self.usec / 1000000.0) - def __str__(s): + def __str__(self): msg = "event at {:f}, code {:02d}, type {:02d}, val {:02d}" - return msg.format(s.timestamp(), s.code, s.type, s.value) + return msg.format(self.timestamp(), self.code, self.type, self.value) - def __repr__(s): + def __repr__(self): msg = "{}({!r}, {!r}, {!r}, {!r}, {!r})" - return msg.format(s.__class__.__name__, s.sec, s.usec, s.type, s.code, s.value) + return msg.format(self.__class__.__name__, self.sec, self.usec, self.type, self.code, self.value) class KeyEvent: @@ -119,8 +119,8 @@ def __str__(self): msg = "key event at {:f}, {} ({}), {}" return msg.format(self.event.timestamp(), self.scancode, self.keycode, ks) - def __repr__(s): - return "{}({!r})".format(s.__class__.__name__, s.event) + def __repr__(self): + return "{}({!r})".format(self.__class__.__name__, self.event) class RelEvent: @@ -136,8 +136,8 @@ def __str__(self): msg = "relative axis event at {:f}, {}" return msg.format(self.event.timestamp(), REL[self.event.code]) - def __repr__(s): - return "{}({!r})".format(s.__class__.__name__, s.event) + def __repr__(self): + return "{}({!r})".format(self.__class__.__name__, self.event) class AbsEvent: @@ -153,8 +153,8 @@ def __str__(self): msg = "absolute axis event at {:f}, {}" return msg.format(self.event.timestamp(), ABS[self.event.code]) - def __repr__(s): - return "{}({!r})".format(s.__class__.__name__, s.event) + def __repr__(self): + return "{}({!r})".format(self.__class__.__name__, self.event) class SynEvent: @@ -173,8 +173,8 @@ def __str__(self): msg = "synchronization event at {:f}, {}" return msg.format(self.event.timestamp(), SYN[self.event.code]) - def __repr__(s): - return "{}({!r})".format(s.__class__.__name__, s.event) + def __repr__(self): + return "{}({!r})".format(self.__class__.__name__, self.event) #: A mapping of event types to :class:`InputEvent` sub-classes. Used diff --git a/evdev/uinput.py b/evdev/uinput.py index c4225d8..756f83c 100644 --- a/evdev/uinput.py +++ b/evdev/uinput.py @@ -272,7 +272,7 @@ def _verify(self): try: m = os.stat(self.devnode)[stat.ST_MODE] if not stat.S_ISCHR(m): - raise + raise OSError except (IndexError, OSError): msg = '"{}" does not exist or is not a character device file ' "- verify that the uinput module is loaded" raise UInputError(msg.format(self.devnode)) From d757b2dd6cefeeb12dab0cbdc73fb39918fcfb39 Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 05:32:54 +0100 Subject: [PATCH 04/18] attempt 2 --- .github/workflows/lint.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index fda6f9d..1f819ff 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,11 +5,16 @@ on: - pull_request jobs: - black: + pylint: runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: + os: [ubuntu-latest] python-version: ["3.12"] + include: + - os: ubuntu-latest + python-version: "3.12" steps: - uses: actions/checkout@v4 From c1f9eb8c6574f196f62dc998c9ea4b5c8b6a4d89 Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 05:34:47 +0100 Subject: [PATCH 05/18] attempt 3 --- .github/workflows/lint.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1f819ff..e98739e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,9 +12,6 @@ jobs: matrix: os: [ubuntu-latest] python-version: ["3.12"] - include: - - os: ubuntu-latest - python-version: "3.12" steps: - uses: actions/checkout@v4 @@ -24,4 +21,6 @@ jobs: python-version: ${{ matrix.python-version }} - name: Check for pylint errors - run: pylint --disable=no-member -E evdev + run: | + python -m pip install pylint + python -m pylint --disable=no-member -E evdev From 8959af9c66c9aad5ac5ac146658a9c82553da5aa Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 05:44:03 +0100 Subject: [PATCH 06/18] attempt 4 --- .github/workflows/lint.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e98739e..b4b8650 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,4 +23,5 @@ jobs: - name: Check for pylint errors run: | python -m pip install pylint - python -m pylint --disable=no-member -E evdev + python setup.py build + python -m pylint --disable=no-member -E build/*/evdev From 1d18734e5488d45e53ccfe541c1d0ab44c7be9d8 Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 05:47:11 +0100 Subject: [PATCH 07/18] attempt 5 --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b4b8650..d2d23ef 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,6 +22,6 @@ jobs: - name: Check for pylint errors run: | - python -m pip install pylint + python -m pip install pylint setuptools python setup.py build python -m pylint --disable=no-member -E build/*/evdev From c1a23515fb96e516fac5c1a1eccbcf0627ba0ae4 Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 05:50:15 +0100 Subject: [PATCH 08/18] attempt 6 --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d2d23ef..33b40ed 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,4 +24,4 @@ jobs: run: | python -m pip install pylint setuptools python setup.py build - python -m pylint --disable=no-member -E build/*/evdev + python -m pylint --disable=no-member -E build/lib*/evdev From c33d52efcd8eda837065ec48834a809e223b097d Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 05:54:21 +0100 Subject: [PATCH 09/18] Add verbose log for a proof it ran --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 33b40ed..d499462 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,4 +24,4 @@ jobs: run: | python -m pip install pylint setuptools python setup.py build - python -m pylint --disable=no-member -E build/lib*/evdev + python -m pylint --disable=no-member --verbose -E build/lib*/evdev From 26aaa550b3d687ce50f90e4f4fb92ea4441c128a Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 06:01:33 +0100 Subject: [PATCH 10/18] Add pytest step --- .github/workflows/test.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..756a61d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: Test + +on: + - push + - pull_request + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + python-version: ["3.12"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Check for pylint errors + # pip install -e . builds _ecodes and such into the evdev directory + run: | + python -m pip install setuptools + python -m pip install -e . + python -m pytest tests From d0a35b47f2fab952cd358a91f5367ae645850756 Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 06:02:38 +0100 Subject: [PATCH 11/18] pytest attempt 2 --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 756a61d..3ee5baa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,9 +20,9 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Check for pylint errors + - name: Run pytest tests # pip install -e . builds _ecodes and such into the evdev directory run: | - python -m pip install setuptools + python -m pip install pytest setuptools python -m pip install -e . python -m pytest tests From 6de2a990a9493fa20ffe35ac5aa718315d345455 Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 06:08:13 +0100 Subject: [PATCH 12/18] pytest attempt 3 --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3ee5baa..7d54042 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,4 +25,5 @@ jobs: run: | python -m pip install pytest setuptools python -m pip install -e . + chmod +0666 /dev/uinput python -m pytest tests From 40177668299edb1cbedc751dbcb78e260faf474a Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 06:10:02 +0100 Subject: [PATCH 13/18] pytest attempt 4 --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d54042..a9cd949 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,5 +25,4 @@ jobs: run: | python -m pip install pytest setuptools python -m pip install -e . - chmod +0666 /dev/uinput - python -m pytest tests + sudo python -m pytest tests From 6910cf6263b7a3d5f2eb773794d522cc799b2bf4 Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 06:10:49 +0100 Subject: [PATCH 14/18] pytest attempt 5 --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a9cd949..3ee56d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,8 @@ jobs: - name: Run pytest tests # pip install -e . builds _ecodes and such into the evdev directory + # sudo required to write to uinputs run: | - python -m pip install pytest setuptools - python -m pip install -e . + sudo python -m pip install pytest setuptools + sudo python -m pip install -e . sudo python -m pytest tests From 8f1f29c2056fc498b3ebe149ed36966ff6ee92bc Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 06:21:07 +0100 Subject: [PATCH 15/18] Fix test_abs_values --- tests/test_uinput.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_uinput.py b/tests/test_uinput.py index 2bf3dc1..b9a24f6 100644 --- a/tests/test_uinput.py +++ b/tests/test_uinput.py @@ -66,12 +66,12 @@ def test_enable_events(c): def test_abs_values(c): e = ecodes - c["events"] = { + c = { e.EV_KEY: [e.KEY_A, e.KEY_B], - e.EV_ABS: [(e.ABS_X, (0, 255, 0, 0)), (e.ABS_Y, device.AbsInfo(0, 255, 5, 10, 0, 0))], + e.EV_ABS: [(e.ABS_X, (0, 0, 255, 0, 0)), (e.ABS_Y, device.AbsInfo(0, 0, 255, 5, 10, 0))], } - with uinput.UInput(**c) as ui: + with uinput.UInput(events=c) as ui: c = ui.capabilities() abs = device.AbsInfo(value=0, min=0, max=255, fuzz=0, flat=0, resolution=0) assert c[e.EV_ABS][0] == (0, abs) From 3db2afc6c5ab903c39d334f04c6d7afcc30c4bb2 Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 06:22:28 +0100 Subject: [PATCH 16/18] non editable install test --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3ee56d3..404d711 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,9 +21,8 @@ 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 - sudo python -m pip install -e . + sudo python -m pip install . sudo python -m pytest tests From 018961710aa1678a0eedb4b43641d4b6d63482bb Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 06:23:52 +0100 Subject: [PATCH 17/18] revert --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 404d711..3ee56d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,8 +21,9 @@ 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 - sudo python -m pip install . + sudo python -m pip install -e . sudo python -m pytest tests From 0d4cb55244da4e5f73c9b12aa8b9b09d7311ae10 Mon Sep 17 00:00:00 2001 From: sezanzeb <28510156+sezanzeb@users.noreply.github.com> Date: Sun, 19 Jan 2025 10:33:48 +0100 Subject: [PATCH 18/18] Add test for S_ISCHR False --- tests/test_uinput.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/test_uinput.py b/tests/test_uinput.py index b9a24f6..dcd09e0 100644 --- a/tests/test_uinput.py +++ b/tests/test_uinput.py @@ -1,10 +1,12 @@ # encoding: utf-8 - +import stat from select import select -from pytest import raises, fixture +from unittest.mock import patch -from evdev import uinput, ecodes, events, device, util +import pytest +from pytest import raises, fixture +from evdev import uinput, ecodes, device, UInputError # ----------------------------------------------------------------------------- uinput_options = { @@ -114,3 +116,9 @@ def test_write(c): assert evs[3].code == ecodes.KEY_A and evs[3].value == 2 assert evs[4].code == ecodes.KEY_A and evs[4].value == 0 break + + +@patch.object(stat, 'S_ISCHR', return_value=False) +def test_not_a_character_device(c): + with pytest.raises(UInputError): + uinput.UInput(**c)