Skip to content

Commit

Permalink
Fix song skipping in repeat mode, fix localization issues, typing and…
Browse files Browse the repository at this point in the history
… logging fixes (Taiko2k#1321)

* Main: Type up all bare index function vars

* Phazor: Switch all prints to logging module

* Phazor: Fix bugged out extension print when filename had dots in it

* Phazor: Do not advance song in this if block if we are using repeat, fixes Taiko2k#1320

* Phazor: Format code

* Phazor: Fix f-string compat

* Phazor: Fix path exists detection

* Phazor: Fix get_phazor_path() returning str instead of Path

* Phazor: calc_rg can have None passed for the track

* Mark tauon as being Typed

* Fix compiling translations and check for locale folder existence

* print locale dir

---------

Co-authored-by: Taiko2k <Taiko2k@users.noreply.github.com>
  • Loading branch information
C0rn3j and Taiko2k authored Dec 2, 2024
1 parent 58c2a75 commit 1e177f4
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 183 deletions.
19 changes: 12 additions & 7 deletions compile_translations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Compile language files from ./locale"""
import logging
import os
import subprocess
from pathlib import Path

Expand Down Expand Up @@ -51,26 +50,32 @@ def format(self, record: dict) -> str:

def main() -> None:
compile_failure = False
locale_folder = Path("locale").absolute()
script_dir = Path(__file__).parent
locale_folder = script_dir / "locale"
languages = locale_folder.iterdir()

for lang_file in languages:

if lang_file.name == "messages.pot":
continue

po_path = locale_folder / lang_file / "LC_MESSAGES" / "tauon.po"
mo_path = locale_folder / lang_file / "LC_MESSAGES" / "tauon.mo"
po_path = locale_folder / lang_file.name / "LC_MESSAGES" / "tauon.po"
# mo_path = locale_folder / lang_file.name / "LC_MESSAGES" / "tauon.mo"
mo_dirpath = script_dir / "src" / "tauon" / "locale" / lang_file.name / "LC_MESSAGES"
mo_path = mo_dirpath / "tauon.mo"

if not mo_path.exists():
(mo_dirpath).mkdir(parents=True)

if po_path.exists():
try:
subprocess.run(["msgfmt", "-o", mo_path, po_path], check=True)
subprocess.run(["/usr/bin/msgfmt", "-o", mo_path, po_path], check=True)
except Exception:
# Don't log the exception to make the build log clear
logging.error(f"Failed to compile translations for {lang_file}")
logging.error(f"Failed to compile translations for {lang_file.name}")
compile_failure = True
else:
logging.info(f"Compiled: {lang_file}")
logging.info(f"Compiled: {lang_file.name}")

else:
logging.critical(f"Missing po file: {po_path}")
Expand Down
13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# Change the version for the tools below too when bumping up
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3"
"Programming Language :: Python :: 3",
"Typing :: Typed",
]
dynamic = ["dependencies"]

Expand Down Expand Up @@ -65,7 +66,7 @@
dependencies = {file = "requirements.txt"}

[tool.setuptools.package-data]
"tauon" = ["assets/*", "assets/svg/*", "templates/*", "theme/*"]
"tauon" = ["assets/*", "assets/svg/*", "locale/*/*/*.mo", "templates/*", "theme/*"]

# https://github.com/microsoft/pyright/blob/main/docs/configuration.md#pyright-configuration
[tool.pyright]
Expand Down Expand Up @@ -104,6 +105,9 @@
reportUnnecessaryComparison = "error"
reportUnnecessaryContains = "error"
reportUnnecessaryIsInstance = "error"
reportUninitializedInstanceVariable = "warning"
reportUnnecessaryTypeIgnoreComment = "warning"
# reportUnusedCallResult = "warning"
reportUnusedClass = "error"
reportUnusedImport = "error"
reportUnusedFunction = "error"
Expand All @@ -119,9 +123,6 @@
reportMissingSuperCall = "warning"
reportPropertyTypeMismatch = "warning"
reportShadowedImports = "warning"
reportUninitializedInstanceVariable = "warning"
reportUnnecessaryTypeIgnoreComment = "warning"
reportUnusedCallResult = "warning"

# https://docs.astral.sh/ruff/configuration/
[tool.ruff]
Expand Down Expand Up @@ -152,7 +153,7 @@ select = ['ALL']
'D102', # public-method - ^
'D103', # undocumented-public-function - ^
'D104', # undocumented-public-package - ^
#'D105', # undocumented-magic-method - ^ < This one is a bit more severe though
# 'D105', # undocumented-magic-method - ^ < This one is a bit more severe though
'D106', # undocumented-public-nested-class - ^
'D107', # undocumented-public-init - ^
'D400', # ends-in-period - We do not care if docstrings end with a period
Expand Down
1 change: 1 addition & 0 deletions src/tauon/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class CustomLoggingFormatter(logging.Formatter):
format = "%(asctime)s [%(levelname)s] [%(module)s] %(message)s"
format_verbose = "%(asctime)s [%(levelname)s] [%(module)s] %(message)s (%(filename)s:%(lineno)d)"

# TODO(Martin): Add some way in which devel mode uses everything verbose
FORMATS = {
logging.DEBUG: grey_bold + format_verbose + reset,
logging.INFO: yellow + format + reset,
Expand Down
Empty file added src/tauon/py.typed
Empty file.
6 changes: 3 additions & 3 deletions src/tauon/t_modules/t_jellyfin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
from tauon.t_modules.t_extra import TauonPlaylist
from tauon.t_modules.t_main import Tauon, TrackClass

def _(m: str) -> str:
return m
def _(message: str) -> str:
return message

class Jellyfin:

Expand Down Expand Up @@ -86,7 +86,7 @@ def _authenticate(self, debug: bool = False) -> None:
data=json.dumps({ "username": username, "Pw": password }), timeout=(5, 10),
)
except Exception:
logging.exception("Could not establish connection to server. Check server is running and URL is correct.")
logging.exception(f"{_('Could not establish connection to server.')} {_('Check server is running and URL is correct.')}")
self.gui.show_message(_("Could not establish connection to server."), _("Check server is running and URL is correct."), mode="error")
return

Expand Down
Loading

0 comments on commit 1e177f4

Please sign in to comment.