-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Importer restructure #5624
base: master
Are you sure you want to change the base?
Importer restructure #5624
Conversation
responsibilities. I identified the following: - session - state - tasks - stages Should allow to make changes more rapidly in the future.
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.
Pull Request Overview
This PR restructures the importer code by splitting the large importer.py into modular files to isolate different responsibilities and simplify maintenance.
- Split core importer functionalities into dedicated modules: state, session, stages, and tasks.
- Updates the public API in the init.py to reflect the new structure.
- Updates tests to reference the relocated modules.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
beets/importer/state.py | Introduces ImportState with state persistence using pickle. |
beets/importer/init.py | Re-exports public classes and functions, updating API exposure. |
beets/importer/session.py | Implements ImportSession with pipeline setup and session logic. |
test/test_importer.py | Updates import paths to reflect module restructuring. |
Comments suppressed due to low confidence (3)
beets/importer/state.py:92
- Consider using proper logging formatting (e.g., %s) or passing 'exc_info=True' to ensure exceptions are logged correctly.
log.debug("state file could not be read: {0}", exc)
beets/importer/session.py:260
- Creating a new ImportState instance during each element check may lead to performance inefficiencies or inconsistent state; consider reusing an existing instance instead.
[ImportState().progress_has_element(toppath, p) for p in paths]
beets/importer/session.py:182
- [nitpick] Using 'is' for enum comparisons may lead to unexpected behavior; consider using '==' when checking for equality.
elif task.choice_flag is (Action.SKIP):
log.error("state file could not be written: {0}", exc) | ||
|
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.
Consider using proper logging placeholders (e.g., %s) or including 'exc_info=True' to log exception details more effectively.
log.error("state file could not be written: {0}", exc) | |
log.error("state file could not be written: %s", exc, exc_info=True) |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
Description
Hello y'all, when working on the importer.py file in a previous PR I noticed that this file grew quite large and badly needs a restructuring. Restructuring should improve our ability to apply changes to it in the future and isolate sub-functionalities within the importer.
Overview
For now I only changed the structure keeping the code (mostly) unchanged.
I split the functions and classes in the importer.py into the following responsibilities:
importer/session.py
: Includes theImportSession
class.importer/stages.py
: Includes all stage functions, I prefixed the helper functions with a_
to allow distinguishing between stages and helper functions more easily.importer/state.py
: Includes the logic for theImportState
handling i.e. the resume feat.importer/tasks.py
: Includes theImportTask
class and all derived classes. Also includes theAction
enum which I have renamed fromaction
.importer/__init__.py
: Identified all public facing classes and functions and added them to__all__
Potential future changes
I don't want to add this to this PR but there are some places here where I see possible improvements for our code:
Am happy to tackle some of these issues in future PRs if you also think they are worth it.
Best,
Sebastian
Note: This PR is based on #5611 and can only be merged once the typing additions are accepted.