Skip to content

Lastgenre: Separate last.fm client; Centralize extra_debug logging; Group related methods #6368

Merged
snejus merged 10 commits intomasterfrom
lastgenre_split_monolith
Mar 17, 2026
Merged

Lastgenre: Separate last.fm client; Centralize extra_debug logging; Group related methods #6368
snejus merged 10 commits intomasterfrom
lastgenre_split_monolith

Conversation

@JOJ0
Copy link
Copy Markdown
Member

@JOJ0 JOJ0 commented Feb 15, 2026

Description

  • Separation of concerns
    • API client
    • Rest of plugin logic
  • Make tuneloghelper available as extra_debug in logger.py - now usable everywhere in beets.
  • Named types for parsed whitelist and canonicalization tree
  • Group all canonicalization tree processing tools together at the top of the file as plain functions.

New modules

  • client.py - Last.fm API client (LastFmClient) extracted from main plugin

No functional changes - pure refactoring to improve structure.

To Do

  • Documentation.
  • Changelog.
  • Tests. (Adapted existing tests to changes)

@JOJ0 JOJ0 added lastgenre lastgenre plugin plugin Pull requests that are plugins related labels Feb 15, 2026
@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch 2 times, most recently from 9ff6150 to 0f131b5 Compare February 15, 2026 17:42
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 15, 2026

Codecov Report

❌ Patch coverage is 59.49367% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.69%. Comparing base (4b93413) to head (4431aeb).
⚠️ Report is 11 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/lastgenre/client.py 53.19% 21 Missing and 1 partial ⚠️
beetsplug/lastgenre/__init__.py 75.00% 6 Missing and 1 partial ⚠️
beets/logging.py 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6368      +/-   ##
==========================================
+ Coverage   69.68%   69.69%   +0.01%     
==========================================
  Files         144      145       +1     
  Lines       18534    18541       +7     
  Branches     3028     3028              
==========================================
+ Hits        12916    12923       +7     
  Misses       4982     4982              
  Partials      636      636              
Files with missing lines Coverage Δ
beets/logging.py 93.10% <25.00%> (-5.08%) ⬇️
beetsplug/lastgenre/__init__.py 75.54% <75.00%> (+5.32%) ⬆️
beetsplug/lastgenre/client.py 53.19% <53.19%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JOJ0 JOJ0 changed the base branch from master to add-multiple-genres February 19, 2026 05:38
@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch 2 times, most recently from b1e9732 to 22de6ee Compare February 19, 2026 07:44
@snejus snejus force-pushed the add-multiple-genres branch 16 times, most recently from 09fac2f to cc5c589 Compare February 23, 2026 05:11
@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch 2 times, most recently from c1cc917 to 943d6b1 Compare February 26, 2026 17:03
@JOJ0 JOJ0 requested a review from Copilot February 26, 2026 18:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the lastgenre plugin into a modular structure by extracting Last.fm API client, file loaders, and utilities into separate modules. The refactoring maintains all existing functionality while improving code organization and preparing for future enhancements.

Changes:

  • Created four new modules (utils.py, types.py, loaders.py, client.py) to separate concerns
  • Applied factory pattern (from_config()) for configuration-based initialization, consistent with other plugins
  • Moved static helper methods to their logical owners (flatten_tree → DataFileLoader, find_parents → LastGenrePlugin)

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
beetsplug/lastgenre/utils.py New module with shared utilities including make_tunelog() factory for bound logging
beetsplug/lastgenre/types.py New module defining type aliases for Whitelist, CanonTree, and GenreCache
beetsplug/lastgenre/loaders.py New module with DataFileLoader class for loading whitelist and canonicalization tree files
beetsplug/lastgenre/client.py New module with LastFmClient class extracted from main plugin for Last.fm API interactions
beetsplug/lastgenre/init.py Refactored main plugin to use new modular structure, removing ~180 lines of code
test/plugins/test_lastgenre.py Updated tests to reflect new module structure (client methods now accessed via plugin.client)
docs/changelog.rst Added changelog entries documenting the refactoring and separator option removal

Comment thread beetsplug/lastgenre/loaders.py Outdated
Comment thread beetsplug/lastgenre/client.py
Comment thread docs/changelog.rst Outdated
@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch from a3100b6 to cd0dc9b Compare March 7, 2026 07:48
@JOJ0 JOJ0 changed the title Lastgenre: Split last.fm fetching and file loading to separate files Lastgenre: Separate last.fm client; Centralize extra_debug logging; Group related methods Mar 7, 2026
@JOJ0 JOJ0 marked this pull request as ready for review March 7, 2026 08:33
@JOJ0
Copy link
Copy Markdown
Member Author

JOJ0 commented Mar 7, 2026

Hi @snejus we had a chat around this refactor. It is now ready for a review. One thing we did not discuss is that I grouped all the canonicalization helpers together. In my first version I had them put into the classes together with the methods that were in there already and made them staticmethods. Now I like this new approach better. Have a look at c21c207, all pure functions that manipulate a CanonTree. Makes sense?

Also note that I only put the extra_debug tool to the changelog since the rest is just refactoring. Should be enough right? Or add the last.fm separation to that same section "For plugin developers" too?

Comment thread beetsplug/lastgenre/__init__.py
@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch 3 times, most recently from 471a673 to c3d20c2 Compare March 8, 2026 18:01
@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch 4 times, most recently from 8e956ae to 3e1a22a Compare March 15, 2026 21:53
Copy link
Copy Markdown
Member

@snejus snejus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one question regarding making extra_debug a method on BeetsLogger, so that one can do self.log.extra_debug(...).

Comment thread beets/logging.py Outdated
@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch from 3e1a22a to 747f9ed Compare March 17, 2026 06:08
Comment thread beets/logging.py
@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch from f7aced7 to 4431aeb Compare March 17, 2026 06:49
Copy link
Copy Markdown
Member

@snejus snejus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done!

@snejus snejus merged commit 05f0ec3 into master Mar 17, 2026
20 checks passed
@snejus snejus deleted the lastgenre_split_monolith branch March 17, 2026 08:18
@JOJ0 JOJ0 removed the plugin Pull requests that are plugins related label Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lastgenre lastgenre plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants