1- import importlib .resources
21import json
32from pathlib import Path
43from typing import Any
54from dataclasses import dataclass , asdict , field , InitVar
5+ from swingmusic .data import ARTIST_SPLIT_IGNORE_LIST
66from 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
3431def 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
4845class 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 ))
0 commit comments