Skip to content

Commit 40383c8

Browse files
committed
fixed a few config loading issues
1 parent 6262ffa commit 40383c8

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

backend/beets_flask/config/schema.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ class BeetsSchema:
1717
# Besides the beets-flask specific config, we want to ensure type safety
1818
# for those fields of the native beets config that we use ourself.
1919
directory: str = field(default="/music/imported")
20-
ignore: list[str] = field(default_factory=lambda: [])
21-
plugins: list[str] = field(default_factory=lambda: [])
20+
ignore: list[str] = field(
21+
default_factory=lambda: [".*", "*~", "System Volume Information", "lost+found"]
22+
)
23+
plugins: list[str] = field(default_factory=lambda: ["musicbrainz"])
2224

2325
# `import` is a reserved keyword in Python. Eyconf's workaround is an alias.
2426
import_: ImportSection = field(

backend/beets_flask/server/app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
from dataclasses import asdict, is_dataclass
66
from datetime import date, datetime
7+
from pathlib import Path
78
from typing import TYPE_CHECKING, Any
89

910
from quart import Quart
@@ -83,4 +84,8 @@ def default(self, o):
8384
if isinstance(o, Enum):
8485
return o.value
8586

87+
# Path to string
88+
if isinstance(o, Path):
89+
return str(o)
90+
8691
return json.JSONEncoder.default(self, o)

backend/beets_flask/server/routes/library/artists.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@
2323
# Also artistids are not used, but they are in the database.
2424

2525

26-
ARTIST_SEPARATORS: list[str] = get_config().data.gui.library.artist_separators
26+
def artist_separators() -> list[str]:
27+
return get_config().data.gui.library.artist_separators
2728

2829

29-
def _split_pattern(separators: list[str]) -> str:
30+
def split_pattern(separators: list[str]) -> str:
3031
return "|".join(map(re.escape, separators))
3132

3233

33-
ARTIST_SPLIT_PATTERN = _split_pattern(ARTIST_SEPARATORS)
34-
35-
3634
def get_artists_polars(table: str, artist: str | None = None) -> pl.LazyFrame:
3735
"""Get all artists from the database using polars.
3836
@@ -62,8 +60,10 @@ def get_artists_polars(table: str, artist: str | None = None) -> pl.LazyFrame:
6260

6361
# Split the artist string by the specified separators
6462
artists: list[str] | None
65-
if len(ARTIST_SEPARATORS) > 0 and artist is not None:
66-
artists = [a.strip() for a in re.split(ARTIST_SPLIT_PATTERN, artist)]
63+
if len(artist_separators()) > 0 and artist is not None:
64+
artists = [
65+
a.strip() for a in re.split(split_pattern(artist_separators()), artist)
66+
]
6767
elif artist is not None:
6868
artists = [artist.strip()]
6969
else:
@@ -99,14 +99,14 @@ def get_artists_polars(table: str, artist: str | None = None) -> pl.LazyFrame:
9999
df = df.with_columns((pl.col("added") * 1000).alias("added"))
100100

101101
# Split artist strings into lists and explode into separate rows
102-
if len(ARTIST_SEPARATORS) > 0:
102+
if len(artist_separators()) > 0:
103103
# split does not yet support regex...
104104
# see https://github.com/pola-rs/polars/issues/4819
105105
# we do a replace workaround
106106
df = df.with_columns(
107107
pl.col("artist")
108108
.str.replace_all("\uffff", "")
109-
.str.replace_all(ARTIST_SPLIT_PATTERN, "\uffff")
109+
.str.replace_all(split_pattern(artist_separators()), "\uffff")
110110
.str.split("\uffff")
111111
).explode("artist")
112112

@@ -122,7 +122,7 @@ def get_artists_polars(table: str, artist: str | None = None) -> pl.LazyFrame:
122122

123123
if artists is not None:
124124
# If an artist is specified, filter the result
125-
pattern = _split_pattern(artists)
125+
pattern = split_pattern(artists)
126126
df = df.filter(pl.col("artist").str.contains(pattern, literal=False))
127127
# Overwrite if there are multiple artists (i.e. joined by a separator)
128128
if len(artists) > 1:

backend/tests/integration/test_routes/test_library.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ async def test_no_separators(self, client: Client):
135135

136136
# Mock artist_seperators
137137
with mock.patch(
138-
"beets_flask.server.routes.library.artists.ARTIST_SEPARATORS",
139-
[],
138+
"beets_flask.server.routes.library.artists.artist_separators",
139+
lambda: [],
140140
):
141141
response = await client.get("/api_v1/library/artists/Foo; Bar")
142142
data = await response.get_json()

0 commit comments

Comments
 (0)