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

CI(translations), Documentation, Typing and an assortment of fixes #1305

Merged
merged 31 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
53cb10e
venv: Use standard .venv instead of .env
C0rn3j Nov 21, 2024
00a0265
phazor.c: Fix up building on native Windows
C0rn3j Nov 21, 2024
28f8e6b
pyproject.toml: Add notes for native Windows build
C0rn3j Nov 21, 2024
625985a
pyproject.toml: Fix Windows lib notes
C0rn3j Nov 21, 2024
5c2b3d8
run.sh: Account for .zip files too
C0rn3j Nov 21, 2024
159c873
t_main: Spaces to tabs for about 4K more lines
C0rn3j Nov 22, 2024
d74f572
t_main: Fix erroring out on first run settings load
C0rn3j Nov 22, 2024
eb25920
t_main: Remove unused Tauon.temp_audio / stream-audio dir
C0rn3j Nov 22, 2024
c391276
t_webserve: Make already-started error hint more obvious
C0rn3j Nov 22, 2024
4267793
tauon.py: Fix crashing on exit
C0rn3j Nov 22, 2024
b907464
pyproject.toml: Add more MSVC build notes
C0rn3j Nov 22, 2024
0c6008d
main,phazor,stream,tidal: Partially convert to Path
C0rn3j Nov 22, 2024
b684394
main,draw: Capitalize system var to match platform.system()
C0rn3j Nov 22, 2024
d08955a
Build scripts: Touch up comments
C0rn3j Nov 22, 2024
cb40499
main, db_migrate: Migrate cache_directory & download_directory to Path
C0rn3j Nov 22, 2024
56bb80e
t_webserve: Fix prefs type
C0rn3j Nov 22, 2024
8317b0b
main: Convert music_directory to Path
C0rn3j Nov 22, 2024
ea3e569
main: Remove useless arg from no_padding() and type+docstring the fun…
C0rn3j Nov 22, 2024
9a65680
main: Partially a bunch of functions and classes
C0rn3j Nov 22, 2024
1dc64e7
pyproject.toml: Remove debug code
C0rn3j Nov 22, 2024
7cbdf73
run.sh: Remove pointless ./
C0rn3j Nov 22, 2024
52d4153
compile_translations: Add colored logging and actually crash on errors
C0rn3j Nov 22, 2024
18a7b1f
CI: Add compile_translations test
C0rn3j Nov 22, 2024
5f7fb35
CI: Install gettext for translation compilation
C0rn3j Nov 22, 2024
5711aec
CI: It needs sudo...
C0rn3j Nov 22, 2024
6ee13c4
compile_translations: Run all the translations before failing
C0rn3j Nov 22, 2024
4de418c
tauon.py, bootstrap, main: Type Holder, name its variables clearly, u…
C0rn3j Nov 22, 2024
ce8878e
tauon/bootstrap/main: Typing fixes
C0rn3j Nov 22, 2024
e34953c
Remove duplicate pt translations
C0rn3j Nov 22, 2024
dfabc4d
tauon.py: Do not attempt to use /usr/share/TauonMusicBox as an instal…
C0rn3j Nov 22, 2024
d3785c2
main: Log JPEG XL support to DEBUG as we already logged it to INFO fr…
C0rn3j Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/compile_translations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Tauon Linux CI

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.13'
# Install dependencies
# - run: pip install whatever
- run: sudo apt-get update && sudo apt-get install -y gettext
# Build
# - run: python setup.py build
# Test
# - run: python -m pytest tests
# Compile translations
- run: python -m compile_translations
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ lib/
dist/
*.exe
.dev
.env
.venv
src/tauon_music_box.egg-info
kissfft.tar.gz
miniaudio.tar.gz
75 changes: 64 additions & 11 deletions compile_translations.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,82 @@
"""Compile language files from ./locale"""
import logging
import os
import subprocess
from pathlib import Path


# TODO(Martin): import this class from tauon.py instead
class CustomLoggingFormatter(logging.Formatter):
"""Nicely format logging.loglevel logs"""

grey = "\x1b[38;20m"
grey_bold = "\x1b[38;1m"
yellow = "\x1b[33;20m"
yellow_bold = "\x1b[33;1m"
red = "\x1b[31;20m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
format = "%(asctime)s [%(levelname)s] [%(module)s] %(message)s"
format_verbose = "%(asctime)s [%(levelname)s] [%(module)s] %(message)s (%(filename)s:%(lineno)d)"

FORMATS = {
logging.DEBUG: grey_bold + format_verbose + reset,
logging.INFO: yellow + format + reset,
logging.WARNING: yellow_bold + format + reset,
logging.ERROR: red + format + reset,
logging.CRITICAL: bold_red + format_verbose + reset,
}

def format(self, record: dict) -> str:
log_fmt = self.FORMATS.get(record.levelno)
# Remove the miliseconds(%f) from the default string
date_fmt = "%Y-%m-%d %H:%M:%S"
formatter = logging.Formatter(log_fmt, date_fmt)
# Center align + min length things to prevent logs jumping around when switching between different values
record.levelname = f"{record.levelname:^7}"
record.module = f"{record.module:^10}"
return formatter.format(record)

# DEBUG+ to file and std_err
logging.basicConfig(
level=logging.DEBUG,
handlers=[
logging.StreamHandler(),
# logging.FileHandler('/tmp/tauon.log'),
],
)
# INFO+ to std_err
logging.getLogger().handlers[0].setLevel(logging.INFO)
logging.getLogger().handlers[0].setFormatter(CustomLoggingFormatter())

def main() -> None:
locale_folder = "locale"
languages = os.listdir(locale_folder)
compile_failure = False
locale_folder = Path("locale").absolute()
languages = locale_folder.iterdir()

for lang_file in languages:

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

po_path = Path(locale_folder) / lang_file / "LC_MESSAGES" / "tauon.po"
mo_path = Path(locale_folder) / lang_file / "LC_MESSAGES" / "tauon.mo"
po_path = locale_folder / lang_file / "LC_MESSAGES" / "tauon.po"
mo_path = locale_folder / lang_file / "LC_MESSAGES" / "tauon.mo"

if Path(po_path).exists():
subprocess.run(["msgfmt", "-o", mo_path, po_path])
print(f"Compiled: {lang_file}")
if po_path.exists():
try:
subprocess.run(["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}")
compile_failure = True
else:
logging.info(f"Compiled: {lang_file}")

else:
print(f"Missing po file: {po_path}")

print("Done")
logging.critical(f"Missing po file: {po_path}")
if compile_failure:
raise Exception("Compiling had errors!")
logging.info("Done")

if __name__ == "__main__":
main()
12 changes: 0 additions & 12 deletions locale/pt/LC_MESSAGES/tauon.po
Original file line number Diff line number Diff line change
Expand Up @@ -3092,15 +3092,6 @@ msgstr "Desgostar da faixa"
#~ msgid "Broadcast This"
#~ msgstr "Transmitir Isto"

#~ msgid "There are no tracks in this playlist to broadcast."
#~ msgstr "Não há faixas nesta playlist para transmitir."

#~ msgid "You need to start the broadcast web server in settings."
#~ msgstr "É preciso iniciar o servidor de transmissão nas configurações."

#~ msgid "Start Broadcast"
#~ msgstr "Começar Transmissão"

#~ msgid "Ready broadcaster"
#~ msgstr "Preparar Transmissor"

Expand Down Expand Up @@ -3223,9 +3214,6 @@ msgstr "Desgostar da faixa"
#~ msgid "Enable/Disable main MENU functions:"
#~ msgstr "Activar/Desactivar as principais funções do MENU:"

#~ msgid "Client Secret"
#~ msgstr "Segredo do Cliente"

#~ msgid "Mark Missing as Found"
#~ msgstr "Marcar Em Falta como Encontradas"

Expand Down
4 changes: 0 additions & 4 deletions locale/pt_PT/LC_MESSAGES/tauon.po
Original file line number Diff line number Diff line change
Expand Up @@ -3261,10 +3261,6 @@ msgstr "Faixa \"gostada\""
msgid "Un-Loved track"
msgstr "Desgostar da faixa"

#: t_modules/t_main.py:21570
msgid "Broadcast This"
msgstr "Transmitir Isto"

#: t_modules/t_main.py:22705
msgid "There are no tracks in this playlist to broadcast."
msgstr "Não há faixas nesta lista de reprodução para transmitir."
Expand Down
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
[tool.setuptools]
# https://setuptools.pypa.io/en/latest/userguide/ext_modules.html
# This is terribly formatted as in TOML 1.0 it all has to be inline, can only be changed when TOML 1.1 ships

# Windows - MSVC - does not work as PyGobject, GTK, Cairo and et al won't build under MVSC
# One option would be to test https://github.com/wingtk/gvsbuild + https://stackoverflow.com/a/72737752
# ./vcpkg.exe install libsndfile:x64-windows # TODO download the necessities instead of this bundle, libflac at minimum
# ./vcpkg.exe install mpg123:x64-windows # Hack 1.29.3 in first see https://sourceforge.net/p/mpg123/bugs/374/
# ./vcpkg.exe install libsamplerate:x64-windows
# ./vcpkg.exe install libopenmpt:x64-windows
# ./vcpkg.exe install wavpack:x64-windows
# ./vcpkg.exe install libgme:x64-windows
# ./vcpkg.exe install pthreads:x64-windows
# wavpack.lib is trying to be found but it is wavpackdll.lib
# opusfile includes opus libraries without opus/ wtf copy them over
# ext-modules = [
# {name = "phazor", sources = ["src/phazor/kissfft/kiss_fftr.c", "src/phazor/kissfft/kiss_fft.c", "src/phazor/phazor.c"], include-dirs = ["src/phazor/miniaudio", "C:/Users/Yeet/Tauon/src/phazor/miniaudio", "C:/Users/Yeet/Tauon/vcpkg/installed/x64-windows/include", "C:/Users/Yeet/Tauon/src/phazor/kissfft", "C:/Users/Yeet/Tauon/src/phazor/miniaudio"], libraries=["samplerate", "wavpackdll", "opusfile", "ogg", "opus", "vorbisfile", "mpg123", "FLAC", "openmpt", "pthreadVC3", "gme"], library-dirs = ["vcpkg/installed/x64-windows/lib"] },]

# Linux
ext-modules = [
{name = "phazor", sources = ["src/phazor/kissfft/kiss_fftr.c", "src/phazor/kissfft/kiss_fft.c", "src/phazor/phazor.c"], include-dirs = ["/usr/include/opus"], libraries=["samplerate", "wavpack", "opusfile", "vorbisfile", "mpg123", "FLAC", "openmpt", "gme"] },
{name = "phazor-pw", sources = ["src/phazor/kissfft/kiss_fftr.c", "src/phazor/kissfft/kiss_fft.c", "src/phazor/phazor.c"], include-dirs = ["/usr/include/opus"], libraries=["samplerate", "wavpack", "opusfile", "vorbisfile", "mpg123", "FLAC", "openmpt", "gme", "pipewire-0.3"] },]
Expand All @@ -43,6 +59,9 @@
]

[tool.setuptools.dynamic]
# Windows
# dependencies = {file = "requirements_windows.txt"}
# Linux
dependencies = {file = "requirements.txt"}

[tool.setuptools.package-data]
Expand Down
13 changes: 8 additions & 5 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ cd "$(dirname "$0")"

export PYTHONPATH=".":"${PYTHONPATH-}"

rm -rf .env build dist tauon_music_box.egg-info ./src/phazor/kissfft/* ./src/phazor/miniaudio/*
rm -rf .venv build dist tauon_music_box.egg-info src/phazor/kissfft src/phazor/miniaudio
mkdir -p src/phazor/kissfft src/phazor/miniaudio

_kissfftver=131.1.0
_miniaudiocommit=4a5b74bef029b3592c54b6048650ee5f972c1a48
Expand All @@ -20,15 +21,17 @@ fi
tar --strip-components=1 -xvf kissfft.tar.gz -C ./src/phazor/kissfft/
tar --strip-components=1 -xvf miniaudio.tar.gz -C ./src/phazor/miniaudio/

python -m venv .env
source .env/bin/activate
python -m venv .venv
# Windows: .\.venv\Scripts\activate
source .venv/bin/activate
pip install -r requirements.txt
pip install -r requirements_optional.txt
#pip install -r requirements_devel.txt
#pip install -r requirements_windows.txt
pip install build
python -m compile_translations
python -m build --wheel
#python -m installer --destdir=".env" dist/*.whl
pip install --prefix ".env" dist/*.whl --force-reinstall
#python -m installer --destdir=".venv" dist/*.whl
pip install --prefix ".venv" dist/*.whl --force-reinstall

tauonmb "$@"
29 changes: 28 additions & 1 deletion src/phazor/phazor.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#ifdef _WIN32
#define WIN
#include <windows.h>
#define usleep(usec) Sleep((usec) / 1000) // Convert microseconds to milliseconds
#else
#include <unistd.h>
#endif

#ifdef PIPE
Expand All @@ -40,7 +43,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <pthread.h>
#include <time.h>
Expand Down Expand Up @@ -75,6 +77,31 @@
#include "wavpack/wavpack.h"
#include "gme/gme.h"

#include <Python.h>

// Module method definitions (if any)
static PyMethodDef PhazorMethods[] = {
{NULL, NULL, 0, NULL} // Sentinel
};

// Module definition
static struct PyModuleDef phazor_module = {
PyModuleDef_HEAD_INIT,
"phazor", // Module name
NULL, // Module documentation (may be NULL)
-1, // Size of per-interpreter state of the module
PhazorMethods // Methods table
};

#ifdef _WIN32
__declspec(dllexport)
#endif
// Entry point for the module
PyMODINIT_FUNC PyInit_phazor(void) {
return PyModule_Create(&phazor_module);
}


#define BUFF_SIZE 240000 // Decoded data buffer size
#define BUFF_SAFE 100000 // Ensure there is this much space free in the buffer

Expand Down
37 changes: 36 additions & 1 deletion src/tauon/t_modules/t_bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
from __future__ import annotations

#from dataclasses import dataclass
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Callable
from io import TextIOWrapper
from pathlib import Path
from typing import Any

#@dataclass
class Holder:
pass
"""Class that holds variables for forwarding them from tauon.py to t_main.py"""

t_window: Any # SDL_CreateWindow() return type (???)
renderer: Any # SDL_CreateRenderer() return type (???)
logical_size: list[int] # X Y res
window_size: list[int] # X Y res
maximized: bool
scale: float
window_opacity: float
draw_border: bool
transfer_args_and_exit: Callable[[]] # transfer_args_and_exit() - TODO(Martin): This should probably be moved to extra module
old_window_position: tuple [int, int] | None # X Y res
install_directory: Path
pyinstaller_mode: bool
phone: bool
window_default_size: tuple[int, int] # X Y res
window_title: bytes # t_title.encode("utf-8")
fs_mode: bool
t_title: str # "Tauon"
n_version: str # "7.9.0"
t_version: str # "v" + n_version
t_id: str # "tauonmb" | "com.github.taiko2k.tauonmb"
t_agent: str # "TauonMusicBox/7.9.0"
dev_mode: bool
instance_lock: TextIOWrapper | None

holder = Holder()
21 changes: 11 additions & 10 deletions src/tauon/t_modules/t_db_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import copy
import logging
import os
from pathlib import Path
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand All @@ -18,7 +19,7 @@ def database_migrate(
multi_playlist: list[TauonPlaylist],
star_store: StarStore,
a_cache_dir: str,
cache_directory: str,
cache_directory: Path,
config_directory: str,
install_directory: str,
user_directory: str,
Expand Down Expand Up @@ -324,14 +325,14 @@ def database_migrate(
if db_version <= 44:
logging.info("Updating database to version 45")
logging.info("Cleaning cache directory")
for item in os.listdir(cache_directory):
path = os.path.join(cache_directory, item)
if "-lfm." in item or "-ftv." in item or "-dcg." in item:
os.rename(path, os.path.join(a_cache_dir, item))
for item in os.listdir(cache_directory):
path = os.path.join(cache_directory, item)
if os.path.isfile(path):
os.remove(path)
for item in cache_directory.iterdir():
path = cache_directory / item
if "-lfm." in str(item) or "-ftv." in str(item) or "-dcg." in str(item):
path.rename(a_cache_dir / item)
for item in cache_directory.iterdir():
path = cache_directory / item
if path.is_file():
path.unlink()

if db_version <= 45:
logging.info("Updating database to version 46")
Expand All @@ -347,7 +348,7 @@ def database_migrate(

if db_version <= 47:
logging.info("Updating database to version 48")
if os.path.isfile(os.path.join(user_directory, "spot-r-token")):
if Path(Path(user_directory) / "spot-r-token").is_file():
show_message(
_("Welcome to v6.1.0. Due to changes, please re-authorise Spotify"),
_("You can do this by clicking 'Forget Account', then 'Authroise' in Settings > Accounts > Spotify"))
Expand Down
Loading