-
Notifications
You must be signed in to change notification settings - Fork 1.9k
lastgenre: Refactor genre applying and pretend mode #6021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideRefactors genre assignment and pretend-mode handling by extracting common logging/apply logic into a decorator and dedicated methods, updating command and import hooks to use them, auto-enabling force on pretend mode, and streamlining tests with pytest-mock. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This comment was marked as resolved.
This comment was marked as resolved.
--pretend option--pretend option, item to album genre fallback
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- The fallback-to-album genre behavior is currently hard-coded; consider adding a config option to enable or disable track-level fallback for more flexibility.
- In the track processing loop you check
if item.genre:(the old value) instead of testing the lookup result (item_genre), which can cause incorrect logging or assignment—update that condition to useitem_genre.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The fallback-to-album genre behavior is currently hard-coded; consider adding a config option to enable or disable track-level fallback for more flexibility.
- In the track processing loop you check `if item.genre:` (the old value) instead of testing the lookup result (`item_genre`), which can cause incorrect logging or assignment—update that condition to use `item_genre`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Setting this to "ready to review" since I'd like to get this merged before any new feature I have in draft already and to get a sourcery review already.. |
6adab6b to
097591e
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
@sourcery-ai guide @sourcery-ai summary |
|
I think it would be a good idea to add |
This comment was marked as duplicate.
This comment was marked as duplicate.
Ah let me reconsider @snejus: I see you already reviewed the pretend PR from @arsaboo, so if you think this is ready to merge soon, please go ahead you both and finishe it! I can work from there an adapt this PR to only make pretend conditional smarter/shorter with my decorator refactor idea here! I think I misunderstood earlier and you ment it that way @snejus right? |
@snejus ? Was this your intention? |
|
@JOJ0 indeed - it's mostly finished so it's we can finish it there and you can base your work on top of it! |
097591e to
d7a3a1e
Compare
This comment was marked as resolved.
This comment was marked as resolved.
--pretend option, item to album genre fallbackd7a3a1e to
5b2cf75
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `beetsplug/lastgenre/__init__.py:591` </location>
<code_context>
+ item,
+ )
+ else:
+ self._apply_item_genre(item, label, item.genre)
+ if write:
+ item.try_write()
</code_context>
<issue_to_address>
**issue (bug_risk):** Passing item.genre instead of item_genre may result in incorrect genre assignment.
Pass item_genre to _apply_item_genre to ensure the genre field is updated correctly.
</issue_to_address>
### Comment 2
<location> `test/plugins/test_lastgenre.py:175-184` </location>
<code_context>
+def test_pretend_option_skips_library_updates(mocker):
</code_context>
<issue_to_address>
**suggestion (testing):** Consider adding test coverage for pretend mode with both album and singleton (track) operations.
Please add a test for pretend mode with singleton tracks to verify correct behavior and logging.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
b76cd5b to
93610e3
Compare
The feature was removed from this PR.
Removed this feature from this PR. Just refactoring of genre applying/pretend handling now.
Terminology changed to "logging label / stage label" a while ago already. This is fine and consistent with other parts of the code. |
93610e3 to
aaa9be1
Compare
snejus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment regarding making the test simpler and a couple of suggestions how to deduplicate item and album logic further
|
@JOJ0 shall I commit what I've got here? I refactored things exactly as I suggested as I reviewed the PR. |
|
I was about to finally do it this week. Was again out of town this weekend. Yes please, it would help speed up things. Thank you!!! 🙏 |
af0c576 to
8fbdd6e
Compare
- Move item and genre apply to separate helper functions. Have one function for each to not overcomplicate implementation! - Use a decorator log_and_pretend that logs and does the right thing depending on wheter --pretend was passed or not. - Sets --force (internally) automatically if --pretend is given (this is a behavirol change needing discussion)
only one arg is passed to the info log anymore.
Replace the log_and_pretend decorator with a more robust implementation using singledispatchmethod. This simplifies the genre application logic by consolidating logging and processing into dedicated methods. Key changes: - Remove log_and_pretend decorator in favor of explicit dispatch - Add _fetch_and_log_genre method to centralize genre fetching and logging - Log user-configured full object representation instead of specific attributes - Introduce _process singledispatchmethod with type-specific handlers - Use LibModel type hint for broader compatibility - Simplify command handler by removing duplicate album/item logic - Replace manual genre application with try_sync for consistency
a4a5890 to
15d6b05
Compare
15d6b05 to
54a82c6
Compare
54a82c6 to
88011a7
Compare
JOJ0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @snejus! Let's merge it. Can't press approve since I'm the initial author but LGTM. Great idea with the colors and the singledispatch 🤩
|
🫡 |
snejus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird self approval


Description
Shorten final album/genre-apply code. This was longish code already and since the
--pretendoption is here it is even longer, thus I'd like to smarten/shorten that. Also behavior is changed so that--pretendis automatically enabling force mode (-por-fis what the user usually expects to being the opposite of each other, but we can discuss that of course)To Do
Documentation.Not required. No behavioral changes