Skip to content

Move utils from ui to util#6440

Merged
snejus merged 10 commits intomasterfrom
move-utils-from-ui-to-util
Mar 16, 2026
Merged

Move utils from ui to util#6440
snejus merged 10 commits intomasterfrom
move-utils-from-ui-to-util

Conversation

@snejus
Copy link
Member

@snejus snejus commented Mar 14, 2026

Refactor: Extract UI utilities into beets/util

This PR decouples terminal/display utilities from beets/ui by moving them into focused modules under beets/util. No user-facing behaviour changes.

What moved where

Utility From To
colorize, uncolorize, color_len, color_split, ANSI constants beets/ui/__init__.py beets/util/color.py
colordiff, _field_diff, get_model_changes beets/ui/__init__.py beets/util/diff.py
indent, split_into_lines, print_column_layout, print_newline_layout beets/ui/__init__.py beets/util/layout.py

Notable design change in layout.py

print_column_layout / print_newline_layout previously called ui.print_() internally, creating a hard dependency on beets.ui. They are now renamed to get_column_layout / get_newline_layout and converted to generators, yielding lines instead of printing them. The caller (display.py) is responsible for printing via ui.print_().

New public API

get_model_changes is introduced in beets/util/diff.py as the pure, testable function for computing field-level diffs. show_model_changes in beets/ui now delegates to it.

Tests

  • Moved alongside the code: test/util/test_color.py, test/util/test_diff.py, test/util/test_layout.py.
  • Removed duplicate ShowModelChangeTest from test/ui/test_ui.py — coverage is preserved in test/util/test_diff.py.

@snejus snejus requested a review from a team as a code owner March 14, 2026 11:54
@snejus snejus requested review from JOJ0, Serene-Arc and Copilot March 14, 2026 11:54
@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.

@codecov
Copy link

codecov bot commented Mar 14, 2026

Codecov Report

❌ Patch coverage is 87.86885% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.60%. Comparing base (3bcc539) to head (41c835d).
⚠️ Report is 11 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beets/util/layout.py 79.45% 22 Missing and 8 partials ⚠️
beets/ui/commands/import_/display.py 90.90% 2 Missing ⚠️
beetsplug/badfiles.py 33.33% 2 Missing ⚠️
beets/ui/commands/move.py 66.66% 1 Missing ⚠️
beetsplug/fetchart.py 75.00% 1 Missing ⚠️
beetsplug/importsource.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6440      +/-   ##
==========================================
+ Coverage   69.55%   69.60%   +0.04%     
==========================================
  Files         141      144       +3     
  Lines       18498    18524      +26     
  Branches     3026     3026              
==========================================
+ Hits        12867    12893      +26     
  Misses       4995     4995              
  Partials      636      636              
Files with missing lines Coverage Δ
beets/ui/__init__.py 82.19% <100.00%> (-1.57%) ⬇️
beets/ui/commands/import_/session.py 59.22% <100.00%> (+0.17%) ⬆️
beets/ui/commands/update.py 79.31% <100.00%> (+0.24%) ⬆️
beets/util/color.py 100.00% <100.00%> (ø)
beets/util/diff.py 100.00% <100.00%> (ø)
beetsplug/play.py 84.11% <100.00%> (+0.14%) ⬆️
beets/ui/commands/move.py 73.97% <66.66%> (+0.36%) ⬆️
beetsplug/fetchart.py 74.40% <75.00%> (+0.03%) ⬆️
beetsplug/importsource.py 69.11% <75.00%> (ø)
beets/ui/commands/import_/display.py 81.92% <90.90%> (-0.67%) ⬇️
... and 2 more
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Refactors UI utilities out of beets/ui/__init__.py into focused modules under beets/util/ (color, diff, layout). Layout functions are converted from printing directly to yielding lines.

Changes:

  • Moved colorization utilities to beets/util/color.py, diff utilities to beets/util/diff.py, and layout utilities to beets/util/layout.py
  • Converted print_column_layout/print_newline_layout to generators (get_column_layout/get_newline_layout)
  • Relocated tests alongside new modules and removed duplicates from UI tests

Reviewed changes

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

Show a summary per file
File Description
beets/util/color.py New module with ANSI color constants and colorize/uncolorize functions
beets/util/diff.py New module with colordiff, field_diff, get_model_changes
beets/util/layout.py New module with indent, split_into_lines, get_column/newline_layout generators
beets/ui/init.py Removed moved code, delegates to new modules
beets/ui/commands/import_/display.py Updated imports to use new modules
beets/ui/commands/import_/session.py Updated imports to use new modules
beets/ui/commands/move.py Updated import for colordiff
beets/ui/commands/update.py Updated import for colorize
beetsplug/play.py Updated import for colorize
beetsplug/importsource.py Updated import for colorize
beetsplug/fetchart.py Updated import for colorize
beetsplug/badfiles.py Updated import for colorize
test/util/test_color.py New tests for color utilities
test/util/test_diff.py Updated patch path for _colorize
test/util/test_layout.py New tests for layout utilities
test/ui/test_ui.py Removed duplicated ShowModelChangeTest
test/ui/commands/test_import.py Removed duplicated color/layout tests
.git-blame-ignore-revs Added commit hashes for refactor

You can also share your feedback on Copilot code review. Take the survey.

@snejus snejus force-pushed the move-utils-from-ui-to-util branch from df40b1b to c6f7463 Compare March 14, 2026 11:56
@snejus snejus force-pushed the move-utils-from-ui-to-util branch from c6f7463 to 95ccfa7 Compare March 14, 2026 11:57
@snejus snejus force-pushed the move-utils-from-ui-to-util branch from 95ccfa7 to ae3531d Compare March 14, 2026 11:59
@snejus snejus force-pushed the move-utils-from-ui-to-util branch 2 times, most recently from 3180de3 to f62d29a Compare March 14, 2026 13:49
@snejus snejus force-pushed the move-utils-from-ui-to-util branch from f62d29a to 41c835d Compare March 14, 2026 14:08
Copy link
Member

@JOJ0 JOJ0 left a comment

Choose a reason for hiding this comment

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

on small thing commented inline, other than that LGTM

@snejus snejus merged commit 0dd6df8 into master Mar 16, 2026
20 checks passed
@snejus snejus deleted the move-utils-from-ui-to-util branch March 16, 2026 01:28
`new` when `old` is not provided. When `fields` is given, only those
fields are considered. The `mtime` field is always excluded.
"""
old = old or new.get_fresh_from_db()
Copy link
Contributor

Choose a reason for hiding this comment

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

Because this was moved here from show_model_changes, the old in show_model_changes no longer gets set. This causes None to be printed for the track info in mbsync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants