Skip to content

Commit

Permalink
Use lazy logging instead of f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
arya dradjica committed Sep 22, 2024
1 parent 7dc6a97 commit fcf9a78
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion beets/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions beetsplug/bpd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion beetsplug/embedart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions beetsplug/fetchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions beetsplug/fromfilename.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions beetsplug/metasync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions beetsplug/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 8 additions & 4 deletions beetsplug/replaygain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion beetsplug/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fcf9a78

Please sign in to comment.