Repository navigation
Conversation
|
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. |
There was a problem hiding this comment.
🟡 Changes recommended
grug see few real behavior bugs/regressions (import state ordering/legacy decode, CLI path normalization, fetchart path join, archive cleanup check) that can break resume/import/art scan.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
PR move importer world from bytes path to pathlib.Path, so one path type go through importer session/tasks/state/UI and importer-facing plugins.
Changes:
- Switch importer task/session/stage/state APIs from
bytes/strpaths toPath. - Update util + plugins to use
Pathops (.exists(),.is_file(),.rglob()) instead ofos.path+ encode/decode. - Update tests and helpers to assert
Pathvalues at runtime boundary.
File summaries
| File | Description |
|---|---|
| test/ui/commands/test_import.py | Update logfile parsing test to expect Path outputs. |
| test/test_util.py | Update sorted_walk tests for Path roots and relative Path entries. |
| test/test_importer.py | Update importer tests to pass/compare Path and use Path joins. |
| test/plugins/test_convert.py | Update convert plugin test messaging for Path paths. |
| beetsplug/replaygain.py | Update import_end hook signature to list[Path]. |
| beetsplug/mbsubmit.py | Pass Path task paths through picard launch flow. |
| beetsplug/importadded.py | Update replaced-album path tracking to Path and use album.filepath. |
| beetsplug/fetchart.py | Use sorted_walk with Path inputs while collecting candidate images. |
| beetsplug/convert.py | Track temp files as Path and cleanup via Path.is_file(). |
| beets/util/extension.py | Make extension fix/remux helpers operate on Path only. |
| beets/util/init.py | Change sorted_walk to take/return Path values and simplify ignore logic. |
| beets/ui/commands/import_/session.py | Update resume prompt to accept Path. |
| beets/ui/commands/import_/init.py | Change import command plumbing to Path paths + logfile parsing yields Path. |
| beets/test/helper.py | Update import session fixtures to pass Path paths. |
| beets/test/_common.py | Update _common.import_session helper to accept Sequence[Path]. |
| beets/importer/tasks.py | Convert task objects + archive handling + directory discovery to Path. |
| beets/importer/state.py | Convert import state file path handling to Path and update state APIs to Path. |
| beets/importer/stages.py | Update pipeline stages to log and build tasks with Path. |
| beets/importer/session.py | Update import session bookkeeping/merge tracking/resume to Path. |
| beets/events.py | Update importer event typed args to expose Path list. |
Review details
Suppressed comments (1)
beets/importer/state.py:78
- grug see state._open load pickle then assign tagprogress/taghistory direct. old state file likely have bytes/str, but new code expect Path. this break "legacy import state remains readable" from issue/PR text. grug want coerce loaded keys/values to pathlib.Path (decode bytes) at load boundary.
with self.path.open("rb") as f:
state = pickle.load(f)
# Read the states
self.tagprogress = state.get("tagprogress", {})
self.taghistory = state.get("taghistory", set())
- Files reviewed: 20/20 changed files
- Comments generated: 5
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #6994 +/- ##
==========================================
- Coverage 81.02% 80.87% -0.16%
==========================================
Files 150 150
Lines 21228 21221 -7
Branches 3242 3241 -1
==========================================
- Hits 17201 17163 -38
- Misses 3212 3245 +33
+ Partials 815 813 -2
🚀 New features to boost your workflow:
|
658cb4f to
370eb44
Compare
370eb44 to
1097461
Compare
efce878 to
fa1d3fc
Compare
fa1d3fc to
60569a1
Compare
60569a1 to
a6f89bc
Compare
a6f89bc to
8a71663
Compare
8a71663 to
fe3d555
Compare
b1dfe2e to
dff4065
Compare
dff4065 to
33cdb90
Compare
semohr
left a comment
There was a problem hiding this comment.
Thanks! Two small requests/additions.
|
|
||
| all_files_imported = move and not any( | ||
| files for _, _, files in os.walk(util.syspath(self.toppath)) | ||
| p.is_file() for p in self.toppath.rglob("*") |
There was a problem hiding this comment.
Shouldnt this be something like this?
all_files_imported = move and not any(
files for _, _, files in self.toppath.walk()
)There was a problem hiding this comment.
pathlib.Path does not have such a method :(
| # Read the states | ||
| self.tagprogress = state.get("tagprogress", {}) | ||
| self.taghistory = state.get("taghistory", set()) | ||
| # Older state files store `bytes` paths. Re-sort the progress |
There was a problem hiding this comment.
This seems a bit complicated imo. Also I dont really understand why we need a dict now. Can you elaborate?
There was a problem hiding this comment.
This was needed because I changed tagprocess and taghistory to store paths as Path instead of bytes so everything had to be re-sorted.
I kinda changed my mind now and reverted this thing - I think it may make more sense (especially regarding compatibility) to continue storing these paths as bytes?
ecb44eb to
5e29dad
Compare
Two external plugins use sorted walk: 1. beets-filetote 2. beets-copyartifacts
5e29dad to
2c11dc8
Compare
|
@semohr I'm gonna create a separate master-like branch for What do you reckon? |
Depends on: #6991
Pathlib Migration: Importer Paths 🛠️
This continues the
pathlibmigration by moving the whole importer - session, tasks, state, stages and theimportcommand - from rawbytespaths topathlib.Path. ThePathBytesalias is gone, along with most of thesyspath/displayable_path/os.fsencodenoise around it.Key Changes
1.
sorted_walkandalbums_in_dirwork withPath📁AnyStr, which forcedalbums_in_dirto keep a duplicate set ofbytesmulti-disc regexes (MULTIDISC_BYTES_PATTERNS) and to encodeignorepatterns on the fly. Internally they now deal withPathonly.sorted_walkusesPath.iterdir()andPath.match()forignorerules. Yieldeddirs/filesare still relative toroot.MULTIDISC_BYTES_PATTERNSis removed,is_subdir_of_any_in_listusesPath.parentsinstead ofutil.ancestry, andfetchartno longer converts tostrbefore walking.2.
sorted_walkcompatibility shim 🧩beets-filetoteandbeets-copyartifactscallsorted_walkwithbytespaths (andbytesignore patterns in filetote's case) and then concatenate the results asbytes.strandbytespaths andbytesignore patterns keep working. Results come back in the representation of the given path, with aDeprecationWarninguntil 3.0.0 - same approach as theArtResizerand art utils migration.3. Importer uses
Paththroughout 🔄ImportSession.paths,ImportTask.toppath/paths/old_paths,replaced_albumskeys,ImportTaskFactory,ArchiveImportTaskandImportStateare all typed asPath.item.filepath/album.filepathinstead ofitem.path.--from-logfilepaths are normalised intoPathobjects up front, so the separatebyte_paths/byte_paths_from_logfileslists are gone.extension.fix_extensionandextension.remux_mpeglayer3_wavtake and returnPath.4. State file conversion 💾
ImportStateconvertstagprogressandtaghistoryentries toPathwhen the state file is read.bytespaths. Without the conversion incremental imports would re-import every previously imported directory and interrupted imports would not offer to resume.5. Plugins and events 🔌
importeventpathslist[bytes]list[Path]convert_temp_fileslist[bytes]list[Path]importaddedreplaced_album_pathsset[bytes]set[Path]mbsubmitdisplayable_path(p)Pathtosubprocessdirectlyreplaygainimport_endlist[bytes]list[Path]Testing Strategy 🧪
Handle only pathlib.Path in sorted_walk, albums_in_dirtest/test_util.py:sorted_walktests updated forPathinput and output.test/test_importer.py:albums_in_dirtests usePath.typing: Use pathlib.Path in beets.importertest/test_importer.py: updated forPathsignatures, plusTestImportStatecovering conversion of a legacybytesstate file.test/ui/commands/test_import.py,test/plugins/test_convert.py,test/util/test_extension.pyupdated for the new signatures.beets/test/helper.pyandbeets/test/_common.pypassPathobjects to the import session instead ofos.fsencode(...).Add compatibility shim for sorted_walktest/test_util.py:strandbytespaths andbytesignore patterns return results in the given representation and emit aDeprecationWarning.Notes 📝
importevent listeners and anything readingtask.paths,task.toppathortask.old_pathsnow receivePathinstead ofbytes. There's no shim for these, same asLibrary.directoryin pathlib migration: migrateLibrary.directorytopathlib.Path#6991. Of the plugins listed in our docs,beets-originquery(os.path.commonpath(task.paths).decode(...)) will break.PathBytesis removed frombeets.utilandbeets.util.extension.docs/dev/plugins/events.rstis updated for theimportevent.