Skip to content

Commit

Permalink
expand logging on match_to_remote + switch reversed() logic
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-martino committed May 30, 2024
1 parent 9083af0 commit d94cd37
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions musify/libraries/remote/core/processors/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ async def _match_to_remote(self, name: str) -> None:
item for item in source_valid if item not in remote_valid and item not in pl_original
] if not self._remaining else []
missing = self._remaining or [item for item in source if item.has_uri is None]
discount = [item for item in remote if item in pl_original and item in source]

if len(added) + len(removed) + len(missing) == 0:
if len(source_valid) == len(remote_valid):
Expand All @@ -421,10 +420,12 @@ async def _match_to_remote(self, name: str) -> None:
if remote_counts.get(uri) != count:
missing.extend([item for item in source_valid if item.uri == uri])

discount = sum(1 for item in remote if item in pl_original and item in source)
self.matcher.log([name, f"{len(added):>6} items added"])
self.matcher.log([name, f"{len(removed):>6} items removed"])
self.matcher.log([name, f"{len(missing):>6} items in source missing URI"])
self.matcher.log([name, f"{len(discount):>6} items discounted that were in the playlist originally"])
self.matcher.log([name, f"{len(pl_original):>6} items in the playlist at start"])
self.matcher.log([name, f"{discount:>6} discounted items from the source that were in the playlist at start"])
self.matcher.log([name, f"{len(added) - len(removed):>6} total item changes"])

remaining = removed + missing
Expand Down
2 changes: 1 addition & 1 deletion musify/log/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def format_full_func_name(record: logging.LogRecord, width: int = 40) -> None:
path_split.append(PROGRAM_NAME.lower())

# produce fully qualified path
path_split = list(reversed(path_split[:-1]))
path_split = path_split[:-1][::-1]

# truncate long paths by taking first letters of each part until short enough
path = ".".join(path_split)
Expand Down
2 changes: 1 addition & 1 deletion musify/processors/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _convert_expected_to_datetime(self) -> None:
converted.append(exp.date())
elif re.match(r"\d{1,2}[/-]\d{1,2}[/-]\d{2,4}", exp):
# value is a string representation of datetime
digits: list[int] = list(map(int, reversed(exp.split("/"))))
digits: list[int] = list(map(int, exp.split("/")[::-1]))

if len(str(digits[-1])) < 4: # year is not fully qualified, add millennium part
this_millennium = str(date.today().year)[:2]
Expand Down
2 changes: 1 addition & 1 deletion tests/libraries/core/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def test_collection_sort(collection: MusifyCollection):
items = collection.items.copy()

collection.reverse()
assert collection == list(reversed(items))
assert collection == items[::-1]

collection.sort(reverse=True)
assert collection == items
Expand Down
8 changes: 4 additions & 4 deletions tests/processors/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,29 @@ def test_sort_by_field_basic(self, tracks: list[LocalTrack]):
ItemSorter.sort_by_field(tracks)
assert tracks == tracks_original
ItemSorter.sort_by_field(tracks, reverse=True)
assert tracks == list(reversed(tracks_original))
assert tracks == tracks_original[::-1]

def test_sort_by_track_number(self, tracks: list[LocalTrack]):
tracks_sorted = sorted(tracks, key=lambda t: t.track_number)
ItemSorter.sort_by_field(tracks, field=TrackField.TRACK)
assert tracks == tracks_sorted
ItemSorter.sort_by_field(tracks, field=TrackField.TRACK, reverse=True)
assert tracks == list(reversed(tracks_sorted))
assert tracks == tracks_sorted[::-1]

def test_sort_by_date_added(self, tracks: list[LocalTrack]):
tracks_sorted = sorted(tracks, key=lambda t: t.date_added)
ItemSorter.sort_by_field(tracks, field=LocalTrackField.DATE_ADDED)
assert tracks == tracks_sorted
ItemSorter.sort_by_field(tracks, field=LocalTrackField.DATE_ADDED, reverse=True)
assert tracks == list(reversed(tracks_sorted))
assert tracks == tracks_sorted[::-1]

def test_sort_by_title_with_ignore_words(self, tracks: list[LocalTrack]):
# sort on str, ignoring defined words like 'The' and 'A'
tracks_sorted = sorted(tracks, key=lambda t: strip_ignore_words(t.title))
ItemSorter.sort_by_field(tracks, field=TrackField.TITLE)
assert tracks == tracks_sorted
ItemSorter.sort_by_field(tracks, field=TrackField.TITLE, reverse=True)
assert tracks == list(reversed(tracks_sorted))
assert tracks == tracks_sorted[::-1]

def test_group_by_field(self, tracks: list[LocalTrack]):
assert ItemSorter.group_by_field(tracks) == {None: tracks}
Expand Down

0 comments on commit d94cd37

Please sign in to comment.