Skip to content

Commit 890e6fb

Browse files
authored
Merge pull request #2050 from C0rn3j/format
Ruff format, typing & linting
2 parents 9df5665 + e034422 commit 890e6fb

File tree

13 files changed

+1426
-667
lines changed

13 files changed

+1426
-667
lines changed

src/tauon/__main__.py

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
from tauon.t_modules.t_bootstrap import Holder # noqa: E402
3535
from tauon.t_modules.t_logging import CustomLoggingFormatter, LogHistoryHandler # noqa: E402
3636

37-
pyinstaller_mode = bool(hasattr(sys, "_MEIPASS") or getattr(sys, "frozen", False) or install_directory.name.endswith("_internal"))
37+
pyinstaller_mode = bool(
38+
hasattr(sys, "_MEIPASS") or getattr(sys, "frozen", False) or install_directory.name.endswith("_internal")
39+
)
3840

3941
log = LogHistoryHandler()
4042
formatter = logging.Formatter("[%(levelname)s] %(message)s")
@@ -46,7 +48,7 @@
4648
handlers=[
4749
logging.StreamHandler(),
4850
log,
49-
# logging.FileHandler('/tmp/tauon.log'),
51+
# logging.FileHandler('/tmp/tauon.log'),
5052
],
5153
)
5254
logging.getLogger().handlers[0].setFormatter(CustomLoggingFormatter())
@@ -55,13 +57,14 @@
5557
logging.captureWarnings(capture=True)
5658
if not sys.warnoptions:
5759
import warnings
60+
5861
warnings.simplefilter("default")
59-
os.environ["PYTHONWARNINGS"] = "default" # Also affect subprocesses
62+
os.environ["PYTHONWARNINGS"] = "default" # Also affect subprocesses
6063

6164
if sys.platform != "win32":
6265
import fcntl
6366

64-
n_version = "9.1.0" # Should also be bumped in pyproject.toml, extra/*.appdata.xml
67+
n_version = "9.1.0" # Should also be bumped in pyproject.toml, extra/*.appdata.xml
6568
t_version = "v" + n_version
6669
t_title = "Tauon"
6770
t_id = "tauonmb"
@@ -72,12 +75,15 @@
7275

7376
logging.info(f"Started with arguments: {sys.argv}")
7477

78+
7579
def open_discord() -> None:
7680
webbrowser.open("https://discord.gg/v4EmhES")
7781

82+
7883
def open_github() -> None:
7984
webbrowser.open("https://github.com/Taiko2k/Tauon/issues")
8085

86+
8187
def open_crash_log(path: Path) -> None:
8288
try:
8389
if sys.platform == "win32":
@@ -89,24 +95,33 @@ def open_crash_log(path: Path) -> None:
8995
except Exception:
9096
webbrowser.open(path.as_uri())
9197

98+
9299
def main() -> None:
93100
"""Launch Tauon by means of importing t_main.py"""
94101
from tauon.t_modules.t_main import main as t_main
102+
95103
t_main(holder)
96104

105+
97106
def transfer_args_and_exit() -> None:
98107
"""Early arg processing"""
99108
import urllib.request
109+
100110
base = "http://localhost:7813/"
101111

102112
if len(sys.argv) <= 1:
103113
url = base + "raise/"
104114
urllib.request.urlopen(url)
105115

106116
for item in sys.argv:
107-
108-
if not item.endswith(".py") and not item.startswith("-") and not item.endswith("exe") and (item.startswith("file://") or Path(item).exists()):
117+
if (
118+
not item.endswith(".py")
119+
and not item.startswith("-")
120+
and not item.endswith("exe")
121+
and (item.startswith("file://") or Path(item).exists())
122+
):
109123
import base64
124+
110125
url = base + "open/" + base64.urlsafe_b64encode(item.encode()).decode()
111126
urllib.request.urlopen(url)
112127
if item == "--play-pause":
@@ -141,7 +156,10 @@ def transfer_args_and_exit() -> None:
141156
transfer_args_and_exit()
142157

143158
# If we're installed, use home data locations
144-
install_mode = bool(str(install_directory).startswith(("/opt/", "/usr/", "/app/", "/snap/", "/nix/store/")) or sys.platform in ("darwin", "win32"))
159+
install_mode = bool(
160+
str(install_directory).startswith(("/opt/", "/usr/", "/app/", "/snap/", "/nix/store/"))
161+
or sys.platform in ("darwin", "win32")
162+
)
145163

146164
# Assume that it's a classic Linux install, use standard paths
147165
if str(install_directory).startswith("/usr/") and Path("/usr/share/TauonMusicBox").is_dir():
@@ -157,13 +175,13 @@ def transfer_args_and_exit() -> None:
157175

158176
# Handle regular install, running from a directory and finally a portable install, usually a venv
159177
if install_mode:
160-
# logging.info("Running in installed mode")
178+
# logging.info("Running in installed mode")
161179
user_directory = Path(GLib.get_user_data_dir()) / "TauonMusicBox"
162180
elif install_directory.parent.name == "src":
163-
# logging.info("Running in portable mode from cloned dir")
181+
# logging.info("Running in portable mode from cloned dir")
164182
user_directory = install_directory.parent.parent / "user-data"
165183
else:
166-
# logging.info("Running in portable mode")
184+
# logging.info("Running in portable mode")
167185
user_directory = install_directory / "user-data"
168186

169187
debug = bool((user_directory / "debug").is_file())
@@ -209,7 +227,7 @@ def transfer_args_and_exit() -> None:
209227
# TODO(Martin): Silent crash
210228
transfer_args_and_exit()
211229
if pyinstaller_mode:
212-
os.environ["FONTCONFIG_PATH"] = str(install_directory / "etc" / "fonts") #"C:\\msys64\\mingw64\\etc\\fonts"
230+
os.environ["FONTCONFIG_PATH"] = str(install_directory / "etc" / "fonts") # "C:\\msys64\\mingw64\\etc\\fonts"
213231

214232
phone = False
215233
d = os.environ.get("XDG_CURRENT_DESKTOP")
@@ -219,7 +237,7 @@ def transfer_args_and_exit() -> None:
219237

220238
os.environ["SDL_VIDEO_WAYLAND_ALLOW_LIBDECOR"] = "0" # emergency crash workaround
221239

222-
if pyinstaller_mode: # and sys.platform == 'darwin':
240+
if pyinstaller_mode: # and sys.platform == 'darwin':
223241
os.environ["SDL_BINARY_PATH"] = str(install_directory)
224242

225243
fs_mode = False
@@ -271,7 +289,9 @@ def transfer_args_and_exit() -> None:
271289
# Test the first SetHint to catch if we loaded SDL3 correctly
272290
sethint_result = sdl3.SDL_SetHint(sdl3.SDL_HINT_VIDEO_ALLOW_SCREENSAVER, b"1")
273291
if sethint_result is None:
274-
logging.error("Failed to run SetHint, probably due to https://github.com/Aermoss/PySDL3/issues/35, will try a workaround")
292+
logging.error(
293+
"Failed to run SetHint, probably due to https://github.com/Aermoss/PySDL3/issues/35, will try a workaround"
294+
)
275295
sys.exit(1)
276296

277297
sdl3.SDL_SetHint(sdl3.SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, b"1")
@@ -286,8 +306,8 @@ def transfer_args_and_exit() -> None:
286306
w = 720
287307
h = 1800
288308
window_default_size: tuple[int, int] = (w, h)
289-
window_size: list[int] = [w, h]
290-
logical_size: list[int] = [w, h]
309+
window_size: list[int] = [w, h]
310+
logical_size: list[int] = [w, h]
291311
window_opacity = 1
292312
scale = 1
293313
if sys.platform == "darwin":
@@ -296,7 +316,7 @@ def transfer_args_and_exit() -> None:
296316
scale = 1.3
297317

298318
maximized = False
299-
old_window_position: tuple [int, int] | None = None
319+
old_window_position: tuple[int, int] | None = None
300320

301321
window_p = user_directory / "window.p"
302322
if window_p.is_file() and not fs_mode:
@@ -347,8 +367,11 @@ def transfer_args_and_exit() -> None:
347367
if err and "GLX" in err.decode():
348368
logging.error(f"SDL init error: {err.decode()}")
349369
sdl3.SDL_ShowSimpleMessageBox(
350-
sdl3.SDL_MESSAGEBOX_ERROR, b"Tauon Music Box failed to start :(",
351-
b"Error: " + err + b".\n If you're using Flatpak, try running `$ flatpak update`", None)
370+
sdl3.SDL_MESSAGEBOX_ERROR,
371+
b"Tauon Music Box failed to start :(",
372+
b"Error: " + err + b".\n If you're using Flatpak, try running `$ flatpak update`",
373+
None,
374+
)
352375
sys.exit(1)
353376

354377
window_title = t_title
@@ -376,8 +399,10 @@ def transfer_args_and_exit() -> None:
376399
t_window = sdl3.SDL_CreateWindow( # TODO(Taiko): use SDL_CreateWindowAndRenderer()
377400
window_title,
378401
# o_x, o_y,
379-
logical_size[0], logical_size[1],
380-
flags)
402+
logical_size[0],
403+
logical_size[1],
404+
flags,
405+
)
381406

382407
if not t_window:
383408
logging.error("ERROR CREATING WINDOW!")
@@ -392,18 +417,20 @@ def transfer_args_and_exit() -> None:
392417
if sdl_err and sdl_err.decode() == "x11 not available":
393418
x11_path = user_directory / "x11"
394419
if x11_path.exists():
395-
logging.critical("Disabled Xwayland preference as X11 was not found - Known issue if on Flatpak - https://github.com/Taiko2k/Tauon/issues/1034")
420+
logging.critical(
421+
"Disabled Xwayland preference as X11 was not found - Known issue if on Flatpak - https://github.com/Taiko2k/Tauon/issues/1034"
422+
)
396423
x11_path.unlink()
397424
# TODO(Martin): This does not seem to work on SDL3, it attempts to relaunch under x11 again
398-
#os.environ["SDL_VIDEODRIVER"] = "wayland"
399-
#t_window = sdl3.SDL_CreateWindow(
400-
# window_title,
401-
# o_x, o_y,
402-
# logical_size[0], logical_size[1],
403-
# flags)
404-
#if not t_window:
405-
# logging.error(f"Failed to create Wayland fallback window - SDL Error: {sdl3.SDL_GetError()}")
406-
# sys.exit(1)
425+
# os.environ["SDL_VIDEODRIVER"] = "wayland"
426+
# t_window = sdl3.SDL_CreateWindow(
427+
# window_title,
428+
# o_x, o_y,
429+
# logical_size[0], logical_size[1],
430+
# flags)
431+
# if not t_window:
432+
# logging.error(f"Failed to create Wayland fallback window - SDL Error: {sdl3.SDL_GetError()}")
433+
# sys.exit(1)
407434
sys.exit(1)
408435
else:
409436
logging.critical(f"Failed to find {x11_path} but got 'x11 not available' error, hm?")
@@ -443,7 +470,9 @@ def transfer_args_and_exit() -> None:
443470

444471
logging.info(f"SDL window system: {sdl3.SDL_GetCurrentVideoDriver().decode()}")
445472

446-
sdl3.SDL_SetRenderVSync(renderer, 1) # 1 == enable vsync, 0 == disable, -1 == late swap tearing, 2 == second vertical refresh
473+
sdl3.SDL_SetRenderVSync(
474+
renderer, 1
475+
) # 1 == enable vsync, 0 == disable, -1 == late swap tearing, 2 == second vertical refresh
447476

448477
i_x = pointer(c_int(0))
449478
i_y = pointer(c_int(0))
@@ -479,8 +508,6 @@ def transfer_args_and_exit() -> None:
479508
sdl3.SDL_RenderTexture(renderer, texture, None, rect)
480509

481510

482-
483-
484511
sdl3.SDL_RenderPresent(renderer)
485512

486513
sdl3.SDL_DestroySurface(raw_image)

src/tauon/t_modules/t_db_migrate.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
from __future__ import annotations
44

5-
import copy
65
import logging
7-
from pathlib import Path
86
from typing import TYPE_CHECKING
97

108
from tauon.t_modules.t_extra import RadioPlaylist, RadioStation, StarRecord, TauonPlaylist, TauonQueueItem
119

1210
if TYPE_CHECKING:
13-
from tauon.t_modules.t_main import GuiVar, Prefs, StarStore, Tauon, TrackClass
11+
from pathlib import Path
12+
13+
from tauon.t_modules.t_main import GuiVar, Prefs, Tauon, TrackClass
14+
1415

1516
def migrate_star_store_71(tauon: Tauon) -> None:
1617
import pickle # noqa: PLC0415
@@ -25,9 +26,7 @@ def migrate_star_store_71(tauon: Tauon) -> None:
2526
old_record: list[int | str] = [] # Here just for typing
2627
for key, old_record in tauon.star_store.db.items():
2728
if isinstance(old_record, StarRecord):
28-
logging.warning(
29-
f"Record {old_record} was already a StarRecord, skipping this migration over…"
30-
)
29+
logging.warning(f"Record {old_record} was already a StarRecord, skipping this migration over…")
3130
break
3231
new_record = StarRecord()
3332
new_record.playtime = old_record[0]

src/tauon/t_modules/t_dbus.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242

4343
from tauon.t_modules.t_main import GuiVar, PlayerCtl, Tauon
4444

45-
class MPRIS(dbus.service.Object):
4645

46+
class MPRIS(dbus.service.Object):
4747
def __init__(self, object_path: str, tauon: Tauon) -> None:
48-
self.tauon: Tauon = tauon
49-
self.gui: GuiVar = tauon.gui
48+
self.tauon: Tauon = tauon
49+
self.gui: GuiVar = tauon.gui
5050
self.pctl: PlayerCtl = tauon.pctl
5151
bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
5252
self.bus_name = dbus.service.BusName("org.mpris.MediaPlayer2.tauon", bus) # This object must be kept alive
@@ -161,18 +161,12 @@ def update(self, force: bool = False) -> None:
161161
self.player_properties["Metadata"] = dbus.Dictionary(d, signature="sv")
162162
changed["Metadata"] = self.player_properties["Metadata"]
163163

164-
if (
165-
self.pctl.playing_state == PlayingState.URL_STREAM
166-
and self.player_properties["CanPause"] is True
167-
):
164+
if self.pctl.playing_state == PlayingState.URL_STREAM and self.player_properties["CanPause"] is True:
168165
self.player_properties["CanPause"] = False
169166
self.player_properties["CanSeek"] = False
170167
changed["CanPause"] = self.player_properties["CanPause"]
171168
changed["CanSeek"] = self.player_properties["CanSeek"]
172-
elif (
173-
self.pctl.playing_state == PlayingState.PLAYING
174-
and self.player_properties["CanPause"] is False
175-
):
169+
elif self.pctl.playing_state == PlayingState.PLAYING and self.player_properties["CanPause"] is False:
176170
self.player_properties["CanPause"] = True
177171
self.player_properties["CanSeek"] = True
178172
changed["CanPause"] = self.player_properties["CanPause"]
@@ -208,9 +202,7 @@ def update_shuffle(self) -> None:
208202

209203
def update_loop(self) -> None:
210204
self.player_properties["LoopStatus"] = self.get_loop_status()
211-
self.PropertiesChanged(
212-
"org.mpris.MediaPlayer2.Player", {"LoopStatus": self.get_loop_status()}, []
213-
)
205+
self.PropertiesChanged("org.mpris.MediaPlayer2.Player", {"LoopStatus": self.get_loop_status()}, [])
214206

215207
def get_loop_status(self) -> str:
216208
if self.pctl.repeat_mode:
@@ -309,7 +301,7 @@ def Seek(self, offset: int) -> None:
309301
self.pctl.seek_time(self.pctl.playing_time + (offset / 1000000))
310302

311303
@dbus.service.method(dbus_interface="org.mpris.MediaPlayer2.Player")
312-
def SetPosition(self, id: int, position: str) -> None:
304+
def SetPosition(self, id: str, position: int) -> None:
313305
self.pctl.seek_time(position / 1000000)
314306

315307
self.player_properties["Position"] = dbus.Int64(int(position))

src/tauon/t_modules/t_enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class GuiMode(IntEnum):
5050
MAIN = 1
5151
MINI = 3
5252

53+
5354
class QueueType(IntEnum):
5455
TRACK = 0
5556
ALBUM = 1

0 commit comments

Comments
 (0)