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
@@ -16,7 +16,7 @@ class AppName:
|
||||
return None
|
||||
|
||||
desktop_app_name = wmclass
|
||||
with open(os.path.join(self.path, desktop_file), "r") as f:
|
||||
with open(os.path.join(self.path, desktop_file)) as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
if line.startswith("Name="):
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from fabric.utils import logger
|
||||
import threading
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from typing import Dict, Optional, Tuple
|
||||
|
||||
import httpx
|
||||
from fabric.utils import logger
|
||||
|
||||
|
||||
class CurrencyCache:
|
||||
@@ -102,7 +102,7 @@ class CurrencyCache:
|
||||
except Exception as je:
|
||||
logger.error(f"Failed to parse JSON for {from_code}: {je}")
|
||||
else:
|
||||
print(
|
||||
logger.warning(
|
||||
f"Background fetch for {from_code} returned status {
|
||||
response.status_code
|
||||
}"
|
||||
|
||||
@@ -12,7 +12,7 @@ if not os.path.exists(data.CACHE_DIR):
|
||||
|
||||
class IconResolver:
|
||||
def __init__(
|
||||
self, default_applicaiton_icon: str = "application-x-executable-symbolic"
|
||||
self, default_application_icon: str = "application-x-executable-symbolic"
|
||||
):
|
||||
if os.path.exists(ICON_CACHE_FILE):
|
||||
with open(ICON_CACHE_FILE) as f:
|
||||
@@ -25,7 +25,7 @@ class IconResolver:
|
||||
self._icon_dict = {}
|
||||
|
||||
self._icon_dict_order: list[str] = []
|
||||
self.default_applicaiton_icon = default_applicaiton_icon
|
||||
self.default_application_icon = default_application_icon
|
||||
|
||||
def get_icon_name(self, app_id: str):
|
||||
if app_id in self._icon_dict:
|
||||
@@ -50,11 +50,11 @@ class IconResolver:
|
||||
try:
|
||||
# Fallback to the default application icon.
|
||||
return icon_theme.load_icon(
|
||||
self.default_applicaiton_icon, size, Gtk.IconLookupFlags.FORCE_SIZE
|
||||
self.default_application_icon, size, Gtk.IconLookupFlags.FORCE_SIZE
|
||||
)
|
||||
except GLib.Error as fallback_error:
|
||||
logger.error(
|
||||
f"Error: Fallback icon '{self.default_applicaiton_icon}' also not found. Error: {fallback_error}"
|
||||
f"Error: Fallback icon '{self.default_application_icon}' also not found. Error: {fallback_error}"
|
||||
)
|
||||
return None
|
||||
|
||||
@@ -84,7 +84,7 @@ class IconResolver:
|
||||
except Exception as e:
|
||||
logger.error(f"[ICONS] Error reading desktop file {desktop_file_path}: {e}")
|
||||
|
||||
return self.default_applicaiton_icon
|
||||
return self.default_application_icon
|
||||
|
||||
def _get_desktop_file(self, app_id: str) -> str | None:
|
||||
if not app_id:
|
||||
@@ -131,7 +131,7 @@ class IconResolver:
|
||||
continue
|
||||
path = os.path.join(data_dir, f)
|
||||
try:
|
||||
with open(path, "r", errors="ignore") as file:
|
||||
with open(path, errors="ignore") as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
if line.startswith("StartupWMClass="):
|
||||
@@ -149,7 +149,7 @@ class IconResolver:
|
||||
|
||||
def _compositor_find_icon(self, app_id: str):
|
||||
if not app_id:
|
||||
return self.default_applicaiton_icon
|
||||
return self.default_application_icon
|
||||
|
||||
icon_theme = Gtk.IconTheme.get_default()
|
||||
|
||||
@@ -169,4 +169,4 @@ class IconResolver:
|
||||
if icon and icon_theme.has_icon(icon):
|
||||
return icon
|
||||
|
||||
return self.default_applicaiton_icon
|
||||
return self.default_application_icon
|
||||
@@ -1,7 +1,5 @@
|
||||
from fabric.utils import logger
|
||||
# From https://github.com/stwa/wayland-idle-inhibitor
|
||||
# License: WTFPL Version 2
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import subprocess
|
||||
@@ -9,6 +7,8 @@ import sys
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from fabric.utils import logger
|
||||
|
||||
# Add the project root to sys.path to allow absolute imports from 'utils'
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
@@ -47,10 +47,10 @@ def parse_duration(duration_str: str) -> int:
|
||||
return int(float(duration_str[:-1]))
|
||||
else:
|
||||
return int(duration_str)
|
||||
except ValueError:
|
||||
except ValueError as err:
|
||||
raise ValueError(
|
||||
"Invalid duration format. Use '1h', '30m', '45s', 'on', 'off', etc."
|
||||
)
|
||||
) from err
|
||||
|
||||
|
||||
def kill_existing_inhibit_processes():
|
||||
@@ -183,7 +183,7 @@ def main() -> None:
|
||||
shutdown()
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error: {str(e)}")
|
||||
logger.error(f"Error: {e!s}")
|
||||
logger.error("Make sure you're running this under a Wayland session.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ _services_mod = None
|
||||
def _mod():
|
||||
global _services_mod
|
||||
if _services_mod is None:
|
||||
import services.modus as _services_mod # noqa: F811
|
||||
import services.modus as _services_mod
|
||||
return _services_mod
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user