diff --git a/src/swingmusic/__main__.py b/src/swingmusic/__main__.py index 0c0a835d..4de1b33b 100644 --- a/src/swingmusic/__main__.py +++ b/src/swingmusic/__main__.py @@ -2,12 +2,11 @@ import sys import pathlib import argparse import multiprocessing -from importlib.metadata import version from swingmusic import settings from swingmusic.logger import setup_logger from swingmusic import tools as swing_tools -from swingmusic.settings import AssetHandler +from swingmusic.settings import AssetHandler, Metadata from swingmusic.start_swingmusic import start_swingmusic parser = argparse.ArgumentParser( @@ -17,7 +16,7 @@ parser = argparse.ArgumentParser( ) parser.add_argument( - "-v", "--version", action="version", version=f"swingmusic v{version('swingmusic')}" + "-v", "--version", action="version", version=f"swingmusic v{Metadata.version}" ) parser.add_argument("--host", default="0.0.0.0", help="Host to run the app on.") parser.add_argument( diff --git a/src/swingmusic/config.py b/src/swingmusic/config.py index 5e7ed2ad..0df889fe 100644 --- a/src/swingmusic/config.py +++ b/src/swingmusic/config.py @@ -1,8 +1,8 @@ -import importlib.resources import json from pathlib import Path from typing import Any from dataclasses import dataclass, asdict, field, InitVar +from swingmusic.data import ARTIST_SPLIT_IGNORE_LIST from swingmusic.settings import Paths, Singleton @@ -15,7 +15,7 @@ def load_artist_ignore_list_from_file(filepath: Path) -> set[str]: """ if filepath.exists(): text = filepath.read_text() - return set([ line.strip() for line in text.splitlines() if line.strip() ]) + return set([line.strip() for line in text.splitlines() if line.strip()]) else: return set() @@ -25,10 +25,7 @@ def load_default_artist_ignore_list() -> set[str]: Loads the default artist-ignore-list from the text file. Returns an empty set if the file doesn't exist. """ - text = importlib.resources.read_text("swingmusic.data","artist_split_ignore.txt") - # only return unique and not empty lines - lines = text.splitlines() - return set([ line.strip() for line in lines if line.strip() ]) + return ARTIST_SPLIT_IGNORE_LIST def load_user_artist_ignore_list() -> set[str]: @@ -39,14 +36,14 @@ def load_user_artist_ignore_list() -> set[str]: user_file = Paths().config_dir / "artist_split_ignore.txt" if user_file.exists(): lines = user_file.read_text().splitlines() - return set([ line.strip() for line in lines if line.strip()]) + return set([line.strip() for line in lines if line.strip()]) else: return set() @dataclass class UserConfig(metaclass=Singleton): - _finished: bool = field(default=False, init=False) # if post init succesfully + _finished: bool = field(default=False, init=False) # if post init succesfully _config_path: InitVar[Path] = Path("") _artist_split_ignore_file_name: InitVar[str] = "artist_split_ignore.txt" # NOTE: only auth stuff are used (the others are still reading/writing to db) @@ -91,7 +88,6 @@ class UserConfig(metaclass=Singleton): lastfmApiSecret: str = "5e5306fbf3e8e3bc92f039b6c6c4bd4e" lastfmSessionKeys: dict[str, str] = field(default_factory=dict) - def __post_init__(self, _config_path, _artist_split_ignore_file_name): """ Loads the config file and sets the values to this instance @@ -119,7 +115,6 @@ class UserConfig(metaclass=Singleton): self._config_path = config_path self._finished = True - def setup_config_file(self) -> None: """ Creates the config file with the default settings @@ -130,7 +125,6 @@ class UserConfig(metaclass=Singleton): if not config.exists(): self.write_to_file(asdict(self)) - def load_config(self, path: Path) -> dict[str, Any]: """ Reads the settings from the config file. @@ -138,7 +132,6 @@ class UserConfig(metaclass=Singleton): """ return json.loads(path.read_text()) - def write_to_file(self, settings: dict[str, Any]): """ Writes the settings to the config file @@ -149,7 +142,6 @@ class UserConfig(metaclass=Singleton): with self._config_path.open(mode="w") as f: json.dump(settings, f, indent=4, default=list) - def __setattr__(self, key: str, value: Any) -> None: """ Writes to the config file whenever a value is set @@ -167,4 +159,4 @@ class UserConfig(metaclass=Singleton): if key.startswith("_") or not self._config_path: return - self.write_to_file(asdict(self)) \ No newline at end of file + self.write_to_file(asdict(self)) diff --git a/src/swingmusic/data/__init__.py b/src/swingmusic/data/__init__.py new file mode 100644 index 00000000..690c1bc9 --- /dev/null +++ b/src/swingmusic/data/__init__.py @@ -0,0 +1,15 @@ +ARTIST_SPLIT_IGNORE_LIST = { + "AC/DC", + "Bob marley & the wailers", + "Crosby, Stills, Nash & Young", + "Smith & Thell", + "Peter, Paul & Mary", + "Simon & Garfunkel", + "Judy & Mary", + "Florence & The Machine", + "Belle & Sebastian", + "C&C Music Factory", + "C & C Music Factory", + "FO&O", + "The Product G&B", +} diff --git a/src/swingmusic/data/artist_split_ignore.txt b/src/swingmusic/data/artist_split_ignore.txt deleted file mode 100644 index 6e231f4e..00000000 --- a/src/swingmusic/data/artist_split_ignore.txt +++ /dev/null @@ -1,13 +0,0 @@ -AC/DC -Bob marley & the wailers -Crosby, Stills, Nash & Young -Smith & Thell -Peter, Paul & Mary -Simon & Garfunkel -Judy & Mary -Florence & The Machine -Belle & Sebastian -C&C Music Factory -C & C Music Factory -FO&O -The Product G&B \ No newline at end of file diff --git a/src/swingmusic/settings.py b/src/swingmusic/settings.py index 95246acb..beaa3a64 100644 --- a/src/swingmusic/settings.py +++ b/src/swingmusic/settings.py @@ -90,7 +90,6 @@ class AssetHandler: if (path / "index.html").exists(): return True - log.error("Client zip could not be found. Please provide a valid path.") return False with zipfile.ZipFile(client_zip_path, "r") as zip_ref: