Skip to content

Commit

Permalink
type fixes in ItemMatcher + grammar fixes in howtos
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-martino committed Apr 25, 2024
1 parent 867f29b commit 47349f3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
18 changes: 10 additions & 8 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

4 changes: 2 additions & 2 deletions docs/howto.local.playlist.load-save.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ You can also just have Musify automatically determine the playlist type to load
:language: Python
:lines: 19-21

If you already have some tracks loaded and you want the playlist to only use those tracks instead of loading
the tracks itself, you can pass these pre-loaded tracks to the playlist too.
If you already have some tracks loaded, and you want the playlist to only use those tracks instead of loading
the tracks itself, you can pass these preloaded tracks to the playlist too.

.. literalinclude:: _howto/scripts/local.playlist.load-save.py
:language: Python
Expand Down
4 changes: 2 additions & 2 deletions docs/howto.spotify.load.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ In this example, you will:
.. include:: _howto/setup.logging.txt


Setup the Spotify API
---------------------
Set up the Spotify API
----------------------

1. If you don't already have one, create a `Spotify for Developers <https://developer.spotify.com/dashboard>`_ account.

Expand Down
19 changes: 12 additions & 7 deletions musify/processors/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,15 @@ def _log_algorithm(self, source: MusifyObject, extra: Iterable[str] = ()) -> Non
log.extend(extra)
self.log_messages(log, pad='>')

def _log_test[T: MusifyObject](self, source: T, result: T, test: Any, extra: Iterable[str] = ()) -> None:
def _log_test[T: MusifyObject](self, source: T, result: T | None, test: Any, extra: Iterable[str] = ()) -> None:
"""Wrapper for initially logging a test result in a uniform aligned format"""
algorithm = inspect.stack()[1][0].f_code.co_name.replace("match", "").upper().lstrip("_").replace("_", " ")
log_result = f"> Testing URI: {result.uri}" if hasattr(result, "uri") else "> Test failed"

if result is not None and hasattr(result, "uri"):
log_result = f"> Testing URI: {result.uri}"
else:
log_result = "> Test failed"

log = [source.name, log_result, f"{algorithm:<10}={test:<5}"]
if extra:
log.extend(extra)
Expand Down Expand Up @@ -327,10 +332,10 @@ def match[T: MusifyObject](
]
self._log_match(source=source, result=result, extra=extra)
return result
else:
self._log_test(
source=source, result=result, test=score, extra=[f"NO MATCH: {score:.2f}<{min_score:.2f}"]
)

self._log_test(
source=source, result=result, test=score, extra=[f"NO MATCH: {score:.2f}<{min_score:.2f}"]
)

def _score[T: MusifyObject](
self,
Expand Down Expand Up @@ -419,8 +424,8 @@ def _get_scores[T: MusifyObject](

return scores

@staticmethod
def _get_match_from_scores[T: MusifyObject](
self,
scores: Iterable[tuple[T, dict[TagField, Future[float] | list[list[Future[float]]]]]],
max_score: float,
) -> tuple[T | None, float]:
Expand Down

0 comments on commit 47349f3

Please sign in to comment.