Skip to content

Commit

Permalink
Set minimum req to current actual Python 3.8 instead of 3.9, add Ruff…
Browse files Browse the repository at this point in the history
… for linting and formatting

Also lint/format a bit of files with the new ruleset
  • Loading branch information
C0rn3j committed Sep 10, 2024
1 parent 2fb490b commit 2553eca
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Donation links for kozec, who is the original developer, can be found on the [ol
## Building the package by yourself

### Dependencies
- Python 3.9+
- Python 3.8+
- GTK 3.22+
- [PyGObject](https://live.gnome.org/PyGObject)
- [python-gi-cairo](https://packages.debian.org/sid/python-gi-cairo) and [gir1.2-rsvg-2.0](https://packages.debian.org/sid/gir1.2-rsvg-2.0) on Debian-based distributions (included in PyGObject elsewhere)
Expand Down
16 changes: 16 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
target-version = "py38"

[lint.flake8-quotes]
# Existing codebase was already mostly doublequoted
inline-quotes = 'double'


[format]
# Existing codebase was already mostly doublequoted
quote-style = 'double'
indent-style = 'tab'

[lint]
select = ['ALL']
# W191 - We use tabs like sane people, so disable this atrocious PEP 8 recommendation
ignore = ['W191']
10 changes: 7 additions & 3 deletions scc/controller.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/usr/bin/env python3
from scc.constants import HapticPos
from __future__ import annotations

from typing import TYPE_CHECKING

from scc.constants import HapticPos

if TYPE_CHECKING:
from scc.controller import HapticData
import time

import logging
import time

log = logging.getLogger("SCController")

Expand Down
48 changes: 24 additions & 24 deletions scc/drivers/fake.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
"""
SC Controller - Fake controller driver
"""SC Controller - Fake controller driver.
This driver does nothing by default, unless SCC_FAKES environment variable is
set. If it is, creates as many fake controller devices as integer stored in
Expand All @@ -9,40 +7,42 @@
Created controllers are completely useless. For debuging purposes only.
"""

from __future__ import annotations

import logging
import os
from typing import TYPE_CHECKING

from scc.controller import Controller
import os, logging

if TYPE_CHECKING:
from scc.sccdaemon import SCCDaemon

ENV_VAR = "SCC_FAKES"

if ENV_VAR in os.environ:
log = logging.getLogger("FakeDrv")


def init(daemon, config):

def init(daemon: SCCDaemon, config: dict) -> bool:
return True


def start(daemon):

def start(daemon: SCCDaemon) -> None:
num = int(os.environ[ENV_VAR])
log.debug("Creating %s fake controllers", num)
for x in range(0, num):
for x in range(num):
daemon.add_controller(FakeController(x))


class FakeController(Controller):
def __init__(self, number):
def __init__(self, number: int) -> None:
Controller.__init__(self)
self._number = number
self._id = "fake%s" % (self._number,)


def get_type(self):
self._id = f"fake{self._number}"

def get_type(self) -> str:
return "fake"


def set_led_level(self, level):

def set_led_level(self, level:int) -> None:
log.debug("FakeController %s led level set to %s", self.get_id(), level)


def __repr__(self):
return "<FakeController %s>" % (self.get_id(),)

def __repr__(self) -> str:
return f"<FakeController {self.get_id()}>"
52 changes: 30 additions & 22 deletions scc/drivers/hiddrv.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
#!/usr/bin/env python3
"""
SC Controller - Universal HID driver. For all three universal HID devices.
"""SC Controller - Universal HID driver. For all three universal HID devices.
Borrows bit of code and configuration from evdevdrv.
"""
from scc.lib.hidparse import GlobalItem, LocalItem, MainItem, ItemType
from scc.lib.hidparse import UsagePage, parse_report_descriptor
from scc.lib.hidparse import GenericDesktopPage, AXES
from scc.drivers.usb import register_hotplug_device, unregister_hotplug_device
from scc.drivers.usb import USBDevice
from scc.constants import STICK_PAD_MIN, STICK_PAD_MAX
from scc.constants import SCButtons, ControllerFlags
from scc.drivers.evdevdrv import FIRST_BUTTON, TRIGGERS, parse_axis
import ctypes
import json
import logging
import os
import sys

from scc.constants import STICK_PAD_MAX, STICK_PAD_MIN, ControllerFlags, SCButtons
from scc.controller import Controller
from scc.drivers.evdevdrv import FIRST_BUTTON, TRIGGERS, parse_axis
from scc.drivers.usb import (
USBDevice,
register_hotplug_device,
unregister_hotplug_device,
)
from scc.lib import IntEnum
from scc.lib.hidparse import (
AXES,
GenericDesktopPage,
GlobalItem,
ItemType,
LocalItem,
MainItem,
UsagePage,
parse_report_descriptor,
)
from scc.paths import get_config_path
from scc.tools import find_library
from scc.lib import IntEnum

import os
import json
import ctypes
import sys
import logging
log = logging.getLogger("HID")

DEV_CLASS_HID = 3
Expand Down Expand Up @@ -471,19 +479,19 @@ def recursive_search(pattern, path):
return None


def close(self):
def close(self) -> None:
# Called when pad is disconnected
USBDevice.close(self)
if self._ready:
self.daemon.remove_controller(self)
self._ready = False


def get_type(self):
def get_type(self) -> str:
return "hid"


def _generate_id(self):
def _generate_id(self) -> str:
"""
ID is generated as 'hid0000:1111' where first number is vendor and
2nd product id. If two or more controllers with same vendor/product
Expand All @@ -499,15 +507,15 @@ def _generate_id(self):
return id


def get_id(self):
def get_id(self) -> str:
return self._id


def get_gui_config_file(self):
return self.config_file


def __repr__(self):
def __repr__(self) -> str:
vid, pid = self.device.getVendorID(), self.device.getProductID()
return "<HID %.4x%.4x>" % (vid, pid)

Expand Down

0 comments on commit 2553eca

Please sign in to comment.