Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix song skipping in repeat mode, fix localization issues, typing and logging fixes #1321

Merged
merged 12 commits into from
Dec 2, 2024
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
Loading