Skip to content

Lastgenre: Split last.fm fetching and file loading to separate files#6368

Draft
JOJ0 wants to merge 4 commits intomasterfrom
lastgenre_split_monolith
Draft

Lastgenre: Split last.fm fetching and file loading to separate files#6368
JOJ0 wants to merge 4 commits intomasterfrom
lastgenre_split_monolith

Conversation

@JOJ0
Copy link
Member

@JOJ0 JOJ0 commented Feb 15, 2026

Description

  • Separation of concerns
    • API client
    • file loading
    • plugin logic
  • Factory pattern for configuration-based initialization (follows some ideas as recently seen in a Beets Discogs plugin refactor)
  • Static methods group utilities with their logical owners
    • flatten_tree()DataFileLoader (tree processing)
    • find_parents()LastGenrePlugin (genre canonicalization)
  • Prepare for future features, especially additional datafile loading (artist-based genre blacklist, regex genre spelling normalization)

New modules

  • utils.py - Shared utilities with make_tunelog() factory for bound logging functions
  • client.py - Last.fm API client (LastFmClient) extracted from main plugin
  • loaders.py - Data file loader (DataFileLoader) with from_config() factory pattern
  • types.py - Named types for parsed whitelist and canonicalization tree(prepare for future datafile formats)

No functional changes - pure refactoring to improve structure.

To Do

  • Documentation.
  • Changelog. (Prevent merge conflicts for now -> later)
  • Tests. (Adapted existing tests to changes)

@JOJ0 JOJ0 added lastgenre 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

codecov bot commented Feb 15, 2026

Codecov Report

❌ Patch coverage is 60.81081% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.41%. Comparing base (573dca6) to head (42b0d45).
⚠️ Report is 35 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/lastgenre/client.py 55.10% 21 Missing and 1 partial ⚠️
beetsplug/lastgenre/__init__.py 70.58% 4 Missing and 1 partial ⚠️
beetsplug/lastgenre/utils.py 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6368      +/-   ##
==========================================
+ Coverage   69.32%   69.41%   +0.08%     
==========================================
  Files         141      143       +2     
  Lines       18786    18819      +33     
  Branches     3060     3063       +3     
==========================================
+ Hits        13024    13063      +39     
+ Misses       5117     5110       -7     
- Partials      645      646       +1     
Files with missing lines Coverage Δ
beetsplug/lastgenre/utils.py 75.00% <75.00%> (ø)
beetsplug/lastgenre/__init__.py 76.31% <70.58%> (+5.90%) ⬆️
beetsplug/lastgenre/client.py 55.10% <55.10%> (ø)

... and 5 files with indirect coverage changes

🚀 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
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

@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch 2 times, most recently from fd7f4b1 to 9a3a6ba Compare February 27, 2026 05:59
@JOJ0 JOJ0 marked this pull request as ready for review February 27, 2026 06:04
@JOJ0 JOJ0 requested a review from a team as a code owner February 27, 2026 06:04
@github-actions
Copy link

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

Copy link
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

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

@snejus snejus force-pushed the add-multiple-genres branch from dc2d778 to d0efc62 Compare February 27, 2026 18:34
@snejus snejus self-requested a review as a code owner February 27, 2026 18:34
@snejus snejus force-pushed the add-multiple-genres branch from d0efc62 to a540a81 Compare February 27, 2026 18:36
Base automatically changed from add-multiple-genres to master February 27, 2026 18:42
@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch from 998f9a6 to 751d5d1 Compare February 28, 2026 06:37
@Nukesor Nukesor mentioned this pull request Feb 28, 2026
3 tasks
@JOJ0 JOJ0 requested a review from Copilot March 1, 2026 09:33
Copy link
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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch from bca897c to 74608d2 Compare March 1, 2026 11:08
@JOJ0 JOJ0 requested a review from Copilot March 1, 2026 11:09
Copy link
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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch 2 times, most recently from d16b81c to b740c85 Compare March 1, 2026 13:43
@JOJ0 JOJ0 marked this pull request as draft March 3, 2026 15:54
JOJ0 added 2 commits March 3, 2026 17:35
and tunelog helper to a utils module since we will need it everywhere.
@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch from b740c85 to d70d8e9 Compare March 3, 2026 16:42
@JOJ0 JOJ0 force-pushed the lastgenre_split_monolith branch from d70d8e9 to 42b0d45 Compare March 4, 2026 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lastgenre plugin Pull requests that are plugins related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants