Skip to content

Commit 32420f8

Browse files
committed
fix: importlib import bugs :sigh!
1 parent 506c45c commit 32420f8

File tree

5 files changed

+23
-31
lines changed

5 files changed

+23
-31
lines changed

src/swingmusic/__main__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
import pathlib
33
import argparse
44
import multiprocessing
5-
from importlib.metadata import version
65

76
from swingmusic import settings
87
from swingmusic.logger import setup_logger
98
from swingmusic import tools as swing_tools
10-
from swingmusic.settings import AssetHandler
9+
from swingmusic.settings import AssetHandler, Metadata
1110
from swingmusic.start_swingmusic import start_swingmusic
1211

1312
parser = argparse.ArgumentParser(
@@ -17,7 +16,7 @@
1716
)
1817

1918
parser.add_argument(
20-
"-v", "--version", action="version", version=f"swingmusic v{version('swingmusic')}"
19+
"-v", "--version", action="version", version=f"swingmusic v{Metadata.version}"
2120
)
2221
parser.add_argument("--host", default="0.0.0.0", help="Host to run the app on.")
2322
parser.add_argument(

src/swingmusic/config.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import importlib.resources
21
import json
32
from pathlib import Path
43
from typing import Any
54
from dataclasses import dataclass, asdict, field, InitVar
5+
from swingmusic.data import ARTIST_SPLIT_IGNORE_LIST
66
from swingmusic.settings import Paths, Singleton
77

88

@@ -15,7 +15,7 @@ def load_artist_ignore_list_from_file(filepath: Path) -> set[str]:
1515
"""
1616
if filepath.exists():
1717
text = filepath.read_text()
18-
return set([ line.strip() for line in text.splitlines() if line.strip() ])
18+
return set([line.strip() for line in text.splitlines() if line.strip()])
1919
else:
2020
return set()
2121

@@ -25,10 +25,7 @@ def load_default_artist_ignore_list() -> set[str]:
2525
Loads the default artist-ignore-list from the text file.
2626
Returns an empty set if the file doesn't exist.
2727
"""
28-
text = importlib.resources.read_text("swingmusic.data","artist_split_ignore.txt")
29-
# only return unique and not empty lines
30-
lines = text.splitlines()
31-
return set([ line.strip() for line in lines if line.strip() ])
28+
return ARTIST_SPLIT_IGNORE_LIST
3229

3330

3431
def load_user_artist_ignore_list() -> set[str]:
@@ -39,14 +36,14 @@ def load_user_artist_ignore_list() -> set[str]:
3936
user_file = Paths().config_dir / "artist_split_ignore.txt"
4037
if user_file.exists():
4138
lines = user_file.read_text().splitlines()
42-
return set([ line.strip() for line in lines if line.strip()])
39+
return set([line.strip() for line in lines if line.strip()])
4340
else:
4441
return set()
4542

4643

4744
@dataclass
4845
class UserConfig(metaclass=Singleton):
49-
_finished: bool = field(default=False, init=False) # if post init succesfully
46+
_finished: bool = field(default=False, init=False) # if post init succesfully
5047
_config_path: InitVar[Path] = Path("")
5148
_artist_split_ignore_file_name: InitVar[str] = "artist_split_ignore.txt"
5249
# NOTE: only auth stuff are used (the others are still reading/writing to db)
@@ -91,7 +88,6 @@ class UserConfig(metaclass=Singleton):
9188
lastfmApiSecret: str = "5e5306fbf3e8e3bc92f039b6c6c4bd4e"
9289
lastfmSessionKeys: dict[str, str] = field(default_factory=dict)
9390

94-
9591
def __post_init__(self, _config_path, _artist_split_ignore_file_name):
9692
"""
9793
Loads the config file and sets the values to this instance
@@ -119,7 +115,6 @@ def __post_init__(self, _config_path, _artist_split_ignore_file_name):
119115
self._config_path = config_path
120116
self._finished = True
121117

122-
123118
def setup_config_file(self) -> None:
124119
"""
125120
Creates the config file with the default settings
@@ -130,15 +125,13 @@ def setup_config_file(self) -> None:
130125
if not config.exists():
131126
self.write_to_file(asdict(self))
132127

133-
134128
def load_config(self, path: Path) -> dict[str, Any]:
135129
"""
136130
Reads the settings from the config file.
137131
Returns a dictget_root_dirs
138132
"""
139133
return json.loads(path.read_text())
140134

141-
142135
def write_to_file(self, settings: dict[str, Any]):
143136
"""
144137
Writes the settings to the config file
@@ -149,7 +142,6 @@ def write_to_file(self, settings: dict[str, Any]):
149142
with self._config_path.open(mode="w") as f:
150143
json.dump(settings, f, indent=4, default=list)
151144

152-
153145
def __setattr__(self, key: str, value: Any) -> None:
154146
"""
155147
Writes to the config file whenever a value is set
@@ -167,4 +159,4 @@ def __setattr__(self, key: str, value: Any) -> None:
167159
if key.startswith("_") or not self._config_path:
168160
return
169161

170-
self.write_to_file(asdict(self))
162+
self.write_to_file(asdict(self))

src/swingmusic/data/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ARTIST_SPLIT_IGNORE_LIST = {
2+
"AC/DC",
3+
"Bob marley & the wailers",
4+
"Crosby, Stills, Nash & Young",
5+
"Smith & Thell",
6+
"Peter, Paul & Mary",
7+
"Simon & Garfunkel",
8+
"Judy & Mary",
9+
"Florence & The Machine",
10+
"Belle & Sebastian",
11+
"C&C Music Factory",
12+
"C & C Music Factory",
13+
"FO&O",
14+
"The Product G&B",
15+
}

src/swingmusic/data/artist_split_ignore.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/swingmusic/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def extract_default_client(path: Path) -> bool:
9090
if (path / "index.html").exists():
9191
return True
9292

93-
log.error("Client zip could not be found. Please provide a valid path.")
9493
return False
9594

9695
with zipfile.ZipFile(client_zip_path, "r") as zip_ref:

0 commit comments

Comments
 (0)