From fcf9a7831ad2d7a21830a545db9fcb23d7e6e7b3 Mon Sep 17 00:00:00 2001 From: arya dradjica Date: Sun, 22 Sep 2024 15:36:36 +0200 Subject: [PATCH] Use lazy logging instead of f-strings See: --- beets/importer.py | 2 +- beetsplug/bpd/__init__.py | 4 ++-- beetsplug/embedart.py | 2 +- beetsplug/fetchart.py | 14 +++++++------- beetsplug/fromfilename.py | 6 +++--- beetsplug/metasync/__init__.py | 4 ++-- beetsplug/playlist.py | 6 ++++-- beetsplug/replaygain.py | 12 ++++++++---- beetsplug/spotify.py | 2 +- 9 files changed, 29 insertions(+), 23 deletions(-) diff --git a/beets/importer.py b/beets/importer.py index 36e8a6d1b7..fa34e3c050 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -1582,7 +1582,7 @@ def resolve_duplicates(session, task): if task.choice_flag in (action.ASIS, action.APPLY, action.RETAG): found_duplicates = task.find_duplicates(session.lib) if found_duplicates: - log.debug(f"found duplicates: {[o.id for o in found_duplicates]}") + log.debug("found duplicates: {0}", [o.id for o in found_duplicates]) # Get the default action to follow from config. duplicate_action = config["import"]["duplicate_action"].as_choice( diff --git a/beetsplug/bpd/__init__.py b/beetsplug/bpd/__init__.py index cdbd51e63b..9a3c1ad128 100644 --- a/beetsplug/bpd/__init__.py +++ b/beetsplug/bpd/__init__.py @@ -1111,8 +1111,8 @@ def __init__(self, library, host, port, password, ctrl_port, log): self.lib = library self.player = gstplayer.GstPlayer(self.play_finished) self.cmd_update(None) - log.info(f"Server ready and listening on {host}:{port}") - log.debug(f"Listening for control signals on {host}:{ctrl_port}") + log.info("Server ready and listening on {}:{}", host, port) + log.debug("Listening for control signals on {}:{}", host, ctrl_port) def run(self): self.player.run() diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py index b8b894ad65..31ee6db088 100644 --- a/beetsplug/embedart.py +++ b/beetsplug/embedart.py @@ -149,7 +149,7 @@ def embed_func(lib, opts, args): with open(tempimg, "wb") as f: f.write(response.content) except Exception as e: - self._log.error(f"Unable to save image: {e}") + self._log.error("Unable to save image: {}", e) return items = lib.items(decargs(args)) # Confirm with user. diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 81a5202f2c..70af7a2a04 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -455,14 +455,14 @@ def get_image_urls(url, preferred_width=None): try: response = self.request(url) except requests.RequestException: - self._log.debug(f"{self.NAME}: error receiving response") + self._log.debug("{}: error receiving response", self.NAME) return try: data = response.json() except ValueError: self._log.debug( - f"{self.NAME}: error loading response: {response.text}" + "{}: error loading response: {}", self.NAME, response.text ) return @@ -596,7 +596,7 @@ def get(self, album, plugin, paths): try: data = response.json() except ValueError: - self._log.debug(f"google: error loading response: {response.text}") + self._log.debug("google: error loading response: {}", response.text) return if "error" in data: @@ -1064,7 +1064,7 @@ def get(self, album, plugin, paths): url=images[size], size=self.SIZES[size] ) except ValueError: - self._log.debug(f"lastfm: error loading response: {response.text}") + self._log.debug("lastfm: error loading response: {}", response.text) return @@ -1123,14 +1123,14 @@ def get(self, album, plugin, paths): image_url = album.cover_art_url else: image_url = album.items().get().cover_art_url - self._log.debug(f"Cover art URL {image_url} found for {album}") + self._log.debug("Cover art URL {} found for {}", image_url, album) except (AttributeError, TypeError): - self._log.debug(f"Cover art URL not found for {album}") + self._log.debug("Cover art URL not found for {}", album) return if image_url: yield self._candidate(url=image_url, match=Candidate.MATCH_EXACT) else: - self._log.debug(f"Cover art URL not found for {album}") + self._log.debug("Cover art URL not found for {}", album) return diff --git a/beetsplug/fromfilename.py b/beetsplug/fromfilename.py index 4c64310617..9bcc1b182f 100644 --- a/beetsplug/fromfilename.py +++ b/beetsplug/fromfilename.py @@ -112,7 +112,7 @@ def apply_matches(d, log): for item in d: if not item.artist: item.artist = artist - log.info(f"Artist replaced with: {item.artist}") + log.info("Artist replaced with: {}", item.artist) # No artist field: remaining field is the title. else: @@ -122,11 +122,11 @@ def apply_matches(d, log): for item in d: if bad_title(item.title): item.title = str(d[item][title_field]) - log.info(f"Title replaced with: {item.title}") + log.info("Title replaced with: {}", item.title) if "track" in d[item] and item.track == 0: item.track = int(d[item]["track"]) - log.info(f"Track replaced with: {item.track}") + log.info("Track replaced with: {}", item.track) # Plugin structure and hook into import process. diff --git a/beetsplug/metasync/__init__.py b/beetsplug/metasync/__init__.py index c9e1887596..ccfe4a5eb3 100644 --- a/beetsplug/metasync/__init__.py +++ b/beetsplug/metasync/__init__.py @@ -118,13 +118,13 @@ def func(self, lib, opts, args): try: cls = META_SOURCES[player] except KeyError: - self._log.error(f"Unknown metadata source '{player}'") + self._log.error("Unknown metadata source '{}'", player) try: meta_source_instances[player] = cls(self.config, self._log) except (ImportError, ConfigValueError) as e: self._log.error( - f"Failed to instantiate metadata source {player!r}: {e}" + "Failed to instantiate metadata source {!r}: {}", player, e ) # Avoid needlessly iterating over items diff --git a/beetsplug/playlist.py b/beetsplug/playlist.py index 0c67f0cf6c..c80828557e 100644 --- a/beetsplug/playlist.py +++ b/beetsplug/playlist.py @@ -192,8 +192,10 @@ def update_playlist(self, filename, base_dir): if changes or deletions: self._log.info( - f"Updated playlist {filename} " - f"({changes} changes, {deletions} deletions)" + "Updated playlist {} ({} changes, {} deletions)", + filename, + changes, + deletions, ) beets.util.copy(new_playlist, filename, replace=True) beets.util.remove(new_playlist) diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index 54441341eb..40ba87bf2a 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -509,10 +509,10 @@ def _analyse_item( if self._parse_float(b"M: " + line[1]) >= gating_threshold: n_blocks += 1 self._log.debug( - f"{item}: {n_blocks} blocks over {gating_threshold} LUFS" + "{}: {} blocks over {} LUFS", item, n_blocks, gating_threshold ) - self._log.debug(f"{item}: gain {gain} LU, peak {peak}") + self._log.debug("{}: gain {} LU, peak {}", item, gain, peak) return Gain(gain, peak), n_blocks @@ -1527,14 +1527,18 @@ def command_func( if opts.album: albums = lib.albums(ui.decargs(args)) self._log.info( - f"Analyzing {len(albums)} albums ~ {self.backend_name} backend..." + "Analyzing {} albums ~ {} backend...", + len(albums), + self.backend_name, ) for album in albums: self.handle_album(album, write, force) else: items = lib.items(ui.decargs(args)) self._log.info( - f"Analyzing {len(items)} tracks ~ {self.backend_name} backend..." + "Analyzing {} tracks ~ {} backend...", + len(items), + self.backend_name, ) for item in items: self.handle_track(item, write, force) diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index ec30363aab..05ebb9008f 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -624,7 +624,7 @@ def _output_match_results(self, results): spotify_ids = [track_data["id"] for track_data in results] if self.config["mode"].get() == "open": self._log.info( - f"Attempting to open {self.data_source} with playlist" + "Attempting to open {} with playlist", self.data_source ) spotify_url = "spotify:trackset:Playlist:" + ",".join( spotify_ids