Skip to content

Commit

Permalink
clean up unnecessary list( wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Nov 7, 2023
1 parent 7268d82 commit d7c4141
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion rose/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ def _update_cache_for_releases_executor(
WHERE pt.track_id IN ({','.join(['?'] * len(upd_track_ids))})
ORDER BY pt.playlist_name
""",
list(upd_track_ids),
upd_track_ids,
)
update_playlists = [row["playlist_name"] for row in cursor]

Expand Down
10 changes: 5 additions & 5 deletions rose/cache_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ def test_get_track_logtext(config: Config) -> None:

@pytest.mark.usefixtures("seeded_cache")
def test_list_artists(config: Config) -> None:
artists = list(list_artists(config))
artists = list_artists(config)
assert set(artists) == {
("Techno Man", "Techno Man"),
("Bass Man", "Bass Man"),
Expand All @@ -1233,7 +1233,7 @@ def test_list_artists(config: Config) -> None:

@pytest.mark.usefixtures("seeded_cache")
def test_list_genres(config: Config) -> None:
genres = list(list_genres(config))
genres = list_genres(config)
assert set(genres) == {
("Techno", "Techno"),
("Deep House", "Deep House"),
Expand All @@ -1243,13 +1243,13 @@ def test_list_genres(config: Config) -> None:

@pytest.mark.usefixtures("seeded_cache")
def test_list_labels(config: Config) -> None:
labels = list(list_labels(config))
labels = list_labels(config)
assert set(labels) == {("Silk Music", "Silk Music"), ("Native State", "Native State")}


@pytest.mark.usefixtures("seeded_cache")
def test_list_collages(config: Config) -> None:
collages = list(list_collages(config))
collages = list_collages(config)
assert set(collages) == {"Rose Gold", "Ruby Red"}


Expand Down Expand Up @@ -1346,7 +1346,7 @@ def test_get_collage(config: Config) -> None:

@pytest.mark.usefixtures("seeded_cache")
def test_list_playlists(config: Config) -> None:
playlists = list(list_playlists(config))
playlists = list_playlists(config)
assert set(playlists) == {"Lala Lisa", "Turtle Rabbit"}


Expand Down
30 changes: 16 additions & 14 deletions rose/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import shlex
from dataclasses import dataclass
from pathlib import Path
from typing import Iterable, Iterator

import click

Expand Down Expand Up @@ -92,9 +91,7 @@ def execute_metadata_rule(
click.secho("No matching tracks found", dim=True, italic=True)
click.echo()
return
matcher_audiotags = list(
filter_track_false_positives_using_tags(rule.matcher, fast_search_results)
)
matcher_audiotags = filter_track_false_positives_using_tags(rule.matcher, fast_search_results)
if not matcher_audiotags:
click.secho("No matching tracks found", dim=True, italic=True)
click.echo()
Expand Down Expand Up @@ -181,8 +178,9 @@ def _convert_matcher_to_fts_query(pattern: str) -> str:

def filter_track_false_positives_using_tags(
matcher: MetadataMatcher,
fast_search_results: Iterable[FastSearchResult],
) -> Iterator[AudioTags]:
fast_search_results: list[FastSearchResult],
) -> list[AudioTags]:
rval = []
for fsr in fast_search_results:
tags = AudioTags.from_file(fsr.path)
for field in matcher.tags:
Expand All @@ -200,8 +198,9 @@ def filter_track_false_positives_using_tags(
match = match or (field == "albumartist" and any(matches_pattern(matcher.pattern, x.name) for x in tags.albumartists.all))
# fmt: on
if match:
yield tags
rval.append(tags)
break
return rval


Changes = tuple[str, str | int | None | list[str], str | int | None | list[str]]
Expand Down Expand Up @@ -501,8 +500,9 @@ def fast_search_for_matching_releases(

def filter_track_false_positives_using_read_cache(
matcher: MetadataMatcher,
tracks: Iterable[tuple[CachedTrack, CachedRelease]],
) -> Iterator[tuple[CachedTrack, CachedRelease]]:
tracks: list[tuple[CachedTrack, CachedRelease]],
) -> list[tuple[CachedTrack, CachedRelease]]:
rval = []
for t, r in tracks:
for field in matcher.tags:
match = False
Expand All @@ -519,14 +519,15 @@ def filter_track_false_positives_using_read_cache(
match = match or (field == "albumartist" and any(matches_pattern(matcher.pattern, x.name) for x in r.artists.all))
# fmt: on
if match:
yield t, r
break
rval.append((t, r))
return rval


def filter_release_false_positives_using_read_cache(
matcher: MetadataMatcher,
releases: Iterable[CachedRelease],
) -> Iterator[CachedRelease]:
releases: list[CachedRelease],
) -> list[CachedRelease]:
rval = []
for r in releases:
for field in matcher.tags:
match = False
Expand All @@ -540,5 +541,6 @@ def filter_release_false_positives_using_read_cache(
match = match or (field == "albumartist" and any(matches_pattern(matcher.pattern, x.name) for x in r.artists.all))
# fmt: on
if match:
yield r
rval.append(r)
break
return rval
10 changes: 4 additions & 6 deletions rose/rules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ def test_filter_release_false_positives_with_read_cache(config: Config) -> None:
matcher = MetadataMatcher.parse("albumartist:^Man")
fsresults = fast_search_for_matching_releases(config, matcher)
assert len(fsresults) == 2
cacheresults = list(list_releases(config, [r.id for r in fsresults]))
cacheresults = list_releases(config, [r.id for r in fsresults])
assert len(cacheresults) == 2
filteredresults = list(filter_release_false_positives_using_read_cache(matcher, cacheresults))
filteredresults = filter_release_false_positives_using_read_cache(matcher, cacheresults)
assert not filteredresults


Expand All @@ -350,10 +350,8 @@ def test_filter_track_false_positives_with_read_cache(config: Config) -> None:
matcher = MetadataMatcher.parse("trackartist:^Man")
fsresults = fast_search_for_matching_tracks(config, matcher)
assert len(fsresults) == 3
tracks = list(list_tracks(config, [r.id for r in fsresults]))
tracks = list_tracks(config, [r.id for r in fsresults])
assert len(tracks) == 3
tracks_with_releases = get_releases_associated_with_tracks(config, tracks)
filteredresults = list(
filter_track_false_positives_using_read_cache(matcher, tracks_with_releases)
)
filteredresults = filter_track_false_positives_using_read_cache(matcher, tracks_with_releases)
assert not filteredresults
14 changes: 6 additions & 8 deletions rose/virtualfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,14 +802,12 @@ def readdir(self, p: VirtualPath) -> Iterator[tuple[str, dict[str, Any]]]:
raise llfuse.FUSEError(errno.ENOENT)

if p.artist or p.genre or p.label or p.view in ["Releases", "New", "Recently Added"]:
releases = list(
list_releases_delete_this(
self.config,
sanitized_artist_filter=p.artist,
sanitized_genre_filter=p.genre,
sanitized_label_filter=p.label,
new=True if p.view == "New" else None,
)
releases = list_releases_delete_this(
self.config,
sanitized_artist_filter=p.artist,
sanitized_genre_filter=p.genre,
sanitized_label_filter=p.label,
new=True if p.view == "New" else None,
)
for rls, vname in self.vnames.list_release_paths(p, releases):
yield vname, self.stat("dir", rls.source_path)
Expand Down

0 comments on commit d7c4141

Please sign in to comment.