Ryochan7 / sc-controller

User-mode driver and GTK3 based GUI for Steam Controller
GNU General Public License v2.0
177 stars 23 forks source link

Fix tests on python3.11, run tests in CI #82

Closed ahornby closed 1 year ago

ahornby commented 1 year ago

The Key enum was serializing via str() incorrectly on python 3.11, problem was a mix of usage of scc's own enum and the python stdlib enum, which changed in 3.11 (see https://github.com/python/cpython/issues/94763 )

There was only one reference to the stdlib enum so updated it to call the scc one (removing the scc specific enum.py is left for a future change, would make this one harder to review)

Added a test for Key str() and a github actions CI

chewi commented 1 year ago

I was going to submit a different fix for this that doesn't rely on the bundled enum implentation.

diff --git a/scc/lib/__init__.py b/scc/lib/__init__.py
index 33d1486d..43c73967 100644
--- a/scc/lib/__init__.py
+++ b/scc/lib/__init__.py
@@ -1,3 +1,6 @@
 #!/usr/bin/env python2

 from enum import Enum, IntEnum, unique
+
+class SCIntEnum(int, Enum):
+       pass
diff --git a/scc/uinput.py b/scc/uinput.py
index 013d3871..4de6af30 100644
--- a/scc/uinput.py
+++ b/scc/uinput.py
@@ -28,7 +28,7 @@ from math import pi, copysign, sqrt, fmod
 from scc.lib.libusb1 import timeval
 from scc.tools import find_library
 from scc.cheader import defines
-from scc.lib import IntEnum
+from scc.lib import SCIntEnum

 UNPUT_MODULE_VERSION = 9

@@ -43,16 +43,16 @@ else:
 MAX_FEEDBACK_EFFECTS = 4

 # Keys enum contains all keys and button from linux/uinput.h (KEY_* BTN_*)
-Keys = IntEnum('Keys', {i: CHEAD[i] for i in CHEAD.keys() if (i.startswith('KEY_') or
+Keys = SCIntEnum('Keys', {i: CHEAD[i] for i in CHEAD.keys() if (i.startswith('KEY_') or
                                                                                                                        i.startswith('BTN_'))})
 # Keys enum contains all keys and button from linux/uinput.h (KEY_* BTN_*)
-KeysOnly = IntEnum('KeysOnly', {i: CHEAD[i] for i in CHEAD.keys() if i.startswith('KEY_')})
+KeysOnly = SCIntEnum('KeysOnly', {i: CHEAD[i] for i in CHEAD.keys() if i.startswith('KEY_')})

 # Axes enum contains all axes from linux/uinput.h (ABS_*)
-Axes = IntEnum('Axes', {i: CHEAD[i] for i in CHEAD.keys() if i.startswith('ABS_')})
+Axes = SCIntEnum('Axes', {i: CHEAD[i] for i in CHEAD.keys() if i.startswith('ABS_')})

 # Rels enum contains all rels from linux/uinput.h (REL_*)
-Rels = IntEnum('Rels', {i: CHEAD[i] for i in CHEAD.keys() if i.startswith('REL_')})
+Rels = SCIntEnum('Rels', {i: CHEAD[i] for i in CHEAD.keys() if i.startswith('REL_')})

 # Scan codes for each keys (taken from a logitech keyboard)
 Scans = {

Take your pick!

Ryochan7 commented 1 year ago

Thank you for the changes. Taking some time today to tinker with this source code.