style: enforce consistent codestyle via ruff config and auto-fixes
- Configure ruff: isort, pyupgrade, bugbear, flake8 rules - Auto-fix import sorting, redundant parens, exception chaining - Remove from __future__ import annotations (Python 3.13+) - Convert debug print() to logger calls - Fix typo applicaiton → application in icon_resolver - Remove bare returns in animator setters - Move TYPE_CHECKING imports to runtime where used at runtime
This commit is contained in:
60 files changed
+243
-217
No files matched your search
@@ -1,12 +1,15 @@
|
||||
from fabric.audio import Audio # noqa: F401
|
||||
|
||||
from .battery import Battery # noqa: F401
|
||||
from .brightness import Brightness # noqa: F401
|
||||
from .capslock import CapsLock # noqa: F401
|
||||
from .numlock import NumLock # noqa: F401
|
||||
from .config import ConfigService, on_config_change, start_config_service # noqa: F401
|
||||
from .keyboard_layout import KeyboardLayout # noqa: F401
|
||||
from .network import NetworkClient, Wifi, Ethernet # noqa: F401
|
||||
from .mpris import PlayerService, PlayerManager # noqa: F401
|
||||
from .mpris import PlayerService as MprisPlayer, PlayerManager as MprisPlayerManager # noqa: F401
|
||||
from .modus import ModusService # noqa: F401
|
||||
from .mpris import PlayerManager, PlayerService # noqa: F401
|
||||
from .mpris import PlayerManager as MprisPlayerManager # noqa: F401
|
||||
from .mpris import PlayerService as MprisPlayer # noqa: F401
|
||||
from .network import Ethernet, NetworkClient, Wifi # noqa: F401
|
||||
from .numlock import NumLock # noqa: F401
|
||||
from .todo import TodoService # noqa: F401
|
||||
from .config import on_config_change, start_config_service, ConfigService # noqa: F401
|
||||
from .wallpaper import WallpaperService, create_thumbnail # noqa: F401
|
||||
@@ -179,6 +179,7 @@ class Brightness(Service):
|
||||
return int(f.readline().strip())
|
||||
except Exception:
|
||||
return None
|
||||
return None
|
||||
|
||||
def _update_brightness_cache(self):
|
||||
"""Update brightness cache with current value."""
|
||||
@@ -246,6 +247,7 @@ class Brightness(Service):
|
||||
logger.error(f"Error executing ddcutil async: {e}")
|
||||
|
||||
return self._last_raw if self._last_raw != -1 else 0
|
||||
return None
|
||||
|
||||
@screen_brightness.setter
|
||||
def screen_brightness(self, value: int):
|
||||
|
||||
@@ -7,15 +7,13 @@ changes. It is implemented as a singleton and intended to be reused by any
|
||||
module that needs dynamic configuration.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable, Dict, List, Optional
|
||||
|
||||
from fabric.utils import Gio, GLib, logger, os
|
||||
from tomlkit import document as toml_document
|
||||
from tomlkit import dump as toml_dump
|
||||
from tomlkit import load as toml_load
|
||||
from tomlkit.items import Integer, String, Bool, Array
|
||||
from tomlkit.items import Array, Bool, Integer, String
|
||||
|
||||
from utils.utils import toml_file
|
||||
|
||||
@@ -97,7 +95,7 @@ class ConfigService:
|
||||
def _load_config(self) -> None:
|
||||
try:
|
||||
if os.path.exists(self._config_file):
|
||||
with open(self._config_file, "r") as f:
|
||||
with open(self._config_file) as f:
|
||||
self._config = toml_load(f)
|
||||
else:
|
||||
try:
|
||||
|
||||
@@ -184,17 +184,14 @@ class CachedNotifications(Notifications):
|
||||
@Signal
|
||||
def clear_all(self) -> None:
|
||||
"""Signal emitted when notifications are emptied."""
|
||||
pass
|
||||
|
||||
@Signal
|
||||
def cached_notification_added(self, notification: CachedNotification) -> None:
|
||||
"""Signal emitted when a notification is cached."""
|
||||
pass
|
||||
|
||||
@Signal
|
||||
def cached_notification_removed(self, notification: CachedNotification) -> None:
|
||||
"""Signal emitted when a notification is removed from cache."""
|
||||
pass
|
||||
|
||||
@Property(List[CachedNotification], "readable")
|
||||
def cached_notifications(self) -> List[CachedNotification]:
|
||||
@@ -269,7 +266,7 @@ class CachedNotifications(Notifications):
|
||||
def load_cached_notifications(self) -> dict[int, CachedNotification]:
|
||||
"""Load cached notifications from a JSON file (deserialization)."""
|
||||
try:
|
||||
with open(NOTIFICATION_CACHE_FILE, "r") as file:
|
||||
with open(NOTIFICATION_CACHE_FILE) as file:
|
||||
data = json.load(file) # Load list of serialized notifications
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
# If file doesn't exist or is corrupted, start with empty list
|
||||
|
||||
@@ -21,7 +21,7 @@ STATE_FILE = Path("/tmp/hyprland_gamemode.toml")
|
||||
|
||||
def run_hyprctl(command: str) -> str:
|
||||
"""Run a hyprctl command and return the output (raises on error)."""
|
||||
result = run_command(["hyprctl"] + command.split(), timeout=5)
|
||||
result = run_command(["hyprctl", *command.split()], timeout=5)
|
||||
if result.returncode != 0:
|
||||
raise RuntimeError(f"hyprctl failed: {result.stderr}")
|
||||
return result.stdout.strip()
|
||||
@@ -31,7 +31,7 @@ def _read_state() -> dict:
|
||||
if not STATE_FILE.exists():
|
||||
return {}
|
||||
try:
|
||||
with open(STATE_FILE, "r") as f:
|
||||
with open(STATE_FILE) as f:
|
||||
data = tomlkit.load(f)
|
||||
return dict(data) if data else {}
|
||||
except Exception:
|
||||
|
||||
@@ -61,7 +61,7 @@ class GoogleLens(Service):
|
||||
raise RuntimeError(f"Failed to capture region: {capture_result.stderr}")
|
||||
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to capture region: {e}")
|
||||
raise RuntimeError(f"Failed to capture region: {e}") from e
|
||||
|
||||
def upload_file(self, uploader_url, file_path):
|
||||
url_resp = None
|
||||
|
||||
@@ -66,7 +66,7 @@ class KeyboardLayout(Service):
|
||||
if not self.layout_state_file.exists():
|
||||
return None
|
||||
try:
|
||||
with open(self.layout_state_file, "r") as f:
|
||||
with open(self.layout_state_file) as f:
|
||||
data = tomlkit.load(f)
|
||||
return dict(data) if data else None
|
||||
except Exception as e:
|
||||
|
||||
@@ -50,7 +50,7 @@ def __getattr__(name):
|
||||
def get_notification_service():
|
||||
import sys
|
||||
|
||||
return getattr(sys.modules[__name__], "notification_service")
|
||||
return sys.modules[__name__].notification_service
|
||||
|
||||
|
||||
class ModusService(Service):
|
||||
|
||||
@@ -254,7 +254,7 @@ class Ethernet(Service):
|
||||
):
|
||||
self._device.connect(f"notify::{pn}", lambda *_: self.notifier(pn))
|
||||
|
||||
self._device.connect("notify::speed", lambda *_: print(_))
|
||||
self._device.connect("notify::speed", lambda *_: self.notifier("speed"))
|
||||
|
||||
def notifier(self, pn):
|
||||
self.notify(pn)
|
||||
|
||||
@@ -6,6 +6,7 @@ from pathlib import Path
|
||||
|
||||
# Fabric imports
|
||||
from fabric.core.service import Property, Service
|
||||
from fabric.utils import logger
|
||||
|
||||
# Local imports
|
||||
import shared.data as data
|
||||
@@ -36,7 +37,7 @@ class TodoService(Service):
|
||||
try:
|
||||
callback(event_type, data)
|
||||
except Exception as e:
|
||||
print(f"Error in todo callback: {e}")
|
||||
logger.error(f"Error in todo callback: {e}")
|
||||
|
||||
def _get_todos_file_path(self):
|
||||
"""Returns the path to the todos JSON file"""
|
||||
@@ -48,12 +49,12 @@ class TodoService(Service):
|
||||
"""Load todos from JSON file"""
|
||||
try:
|
||||
if self._file_path.exists():
|
||||
with open(self._file_path, "r", encoding="utf-8") as f:
|
||||
with open(self._file_path, encoding="utf-8") as f:
|
||||
self._todos = json.load(f)
|
||||
else:
|
||||
self._todos = []
|
||||
except Exception as e:
|
||||
print(f"Error loading todos: {e}")
|
||||
logger.error(f"Error loading todos: {e}")
|
||||
self._todos = []
|
||||
|
||||
def _save_todos(self):
|
||||
@@ -62,7 +63,7 @@ class TodoService(Service):
|
||||
with open(self._file_path, "w", encoding="utf-8") as f:
|
||||
json.dump(self._todos, f, indent=2, ensure_ascii=False)
|
||||
except Exception as e:
|
||||
print(f"Error saving todos: {e}")
|
||||
logger.error(f"Error saving todos: {e}")
|
||||
|
||||
@Property(list, "readable")
|
||||
def todos(self):
|
||||
|
||||
Reference in new issue
Block a user