Speed up tests by using `unittest.TestCase` for tests that don't require
directory setup
This PR improves test performance by switching several test classes from
`BeetsTestCase` to standard `unittest.TestCase` when they don't require
the directory setup and teardown overhead. The changes focus on test
classes that:
1. Only test utility functions
2. Don't need temporary directories
3. Don't interact with the filesystem
The PR removes unnecessary imports of `BeetsTestCase` and adds direct
imports of `unittest` where needed. This change reduces the test
execution time by avoiding the expensive setup/teardown steps for tests
that don't require them.
## Description
The current developer documentation feels somewhat cluttered due to
inline auto-generated API references for certain classes. To improve
readability and maintainability, this PR introduces a more streamlined
approach that aligns better with best practices observed in other PyData
ecosystem documentation.
Specifically, this PR:
- Adds a dedicated `api/` folder to the documentation structure.
- Moves all auto-generated references (classes, methods, etc.) to this
folder.
- Enables clean, concise linking to API elements from the narrative
documentation—without interrupting human-written content with large
autogenerated blocks.
This separation makes the documentation easier to navigate and maintain,
while still providing full API reference coverage where needed.
- [x] Documentation
- [x] Changelog
Meta: I was looking for possible contribution opportunities, so I
noticed this in the docs. I assume that the `bite-size` label is
outdated, as there aren't actually any issues with that label. Looks
like https://github.com/beetbox/beets/labels/good%20first%20issue is
currently used.
Note: Further below there's also mention of a `first timers only` label
– that link also yields no results and even gives a message about the
label being invalid. I wasn't sure if/how that should be replaced, so I
didn't touch it. Maybe the sentence I am changing should actually be
moved down and replace the one mentioning `first timers only`?
Adds typings to fetchart; a revised and modernized version of
https://github.com/beetbox/beets/pull/5213.
The former pull request became stale because I did more refactoring
there, in order to express properties of the `Candidate` (whether or not
it is validated) via the type system (motivated by the type state
pattern which is more common in Rust.
The result was a little contentious, since it became a little unclear
what the purpose of the `Candidate` class should even be at that point.
I think this was a case of combining too many things into a single PR.
Thus, this version does not perform any refactoring of that extent. It
does sprinkle in a few `assert`s to make thinks clear for the type
checker.
This PR adds two new features to the Discogs plugin:
1. A new `track_for_id` method that allows users to retrieve singleton
tracks directly by their Discogs ID
- Builds on top of the existing `album_for_id` method
- Searches through the album tracks to find the matching track ID
2. A configurable `search_limit` option to control the number of results
returned by the Discogs metadata search queries
- Default value is set to 5
- Helps improve performance by limiting the number of results processed
- Added proper documentation in the plugin docs
Fixes#4661
Fixes#5788
This PR fixes a regression that occurred when the MusicBrainz autotagger
was moved from core functionality into a standalone plugin. During this
transition, the handling of user-configured `extra_tags` was broken,
causing `beets` to die with `AttributeError` when this option was set.
Key changes in `musicbrainz` plugin
- Properly process values from `extra_tags` using the same logic as
before the migration.
- Centralize common bits from `candidates` and `item_candidates`
implementations under `_search_api` to move this class closer towards
`MetadataSourcePlugin` definition.
- Instead of checking for empty `artist` query, use `va_likely`
parameter to determine whether we should query for Various Artists or
not.
- `album` / `title` is always a truthy string - no need to handle empty
criteria case
- `tracks` list always has at least one track - no need to check for
`len(items)`
Refactor: Centralize release ID extraction
This change introduces a new utility function `extract_release_id` in
`beets.util.id_extractors` to handle the parsing of release IDs (or URLs
containing IDs) for various metadata sources (Spotify, Deezer, Beatport,
Discogs, MusicBrainz, Bandcamp, Tidal).
Key changes:
- Added `extract_release_id` function and `PATTERN_BY_SOURCE` regex
dictionary.
- Converted `MetadataSourcePlugin._get_id` static method to an instance
method which uses the `data_source` property to pick the correct id
extractor.
- Removed the `id_regex` property and updated `_get_id` calls in all
modules.
- Replaced old tests related to ID parsing in individual plugin test
files with `test/util/test_id_extractors.py` that tests the
`extract_release_id` function.
This refactoring simplifies the codebase, reduces redundancy, and makes
it easier to manage and extend ID extraction logic for different
sources.
## Description
Hello y'all, when working on the importer.py file in a previous
[PR](#5611) 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 the `ImportSession` 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 the `ImportState`
handling i.e. the resume feat.
- `importer/tasks.py` : Includes the `ImportTask` class and all derived
classes. Also includes the `Action` enum which I have renamed from
`action`.
- `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:
- There are quite some config parsing related functions in the
ImportSession which could be isolated (see e.g. set_config,
want_resume). Maybe a mixin class which handles the config operations
could be useful?
- The ImportSession should be abstract if it is not used directly (I
think it shouldn't). The function definitions which raise NotImplemented
errors are quite weird imo and could be avoided by making the class
abstract.
- For me it was difficult to understand the flow of the importer as
stages call session function and it is not clear which function is
called by which stage and when. Maybe a naming convention for the stage
functions in conjunction with the session methods could help here. Not
sure how this will look in practice but right now it is quite hard to
follow imo. Alternatively splitting the session into a outfacing session
and a session context which is passed to the stages could help.
- The use of the stage decorator is highly inconsistent. Maybe a better
way to handle the stages could be found. This is more of a pipeline
related issue and not directly related to the restructuring but I think
it is worth mentioning.
- Similar to the ImportSession, I think the ImportTask should be
abstract as well, maybe we can put a bit more thought into the task
hierarchy. This might also automatically improve the flow of the
importer pipeline.
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.
# Move MusicBrainz autotagger from core to plugin
Fixes#2686Fixes#4605
This PR relocates the MusicBrainz autotagger functionality from the
beets core into a dedicated plugin. This promotes better code
organization and follows beets' modular design approach.
Key changes:
- Move code from `beets/autotag/mb.py` to new `beetsplug/musicbrainz.py`
- Update default config to include 'musicbrainz' in the plugins list
- Refactor related plugin APIs for better integration
- Update documentation with new musicbrainz plugin page
Impact for users: If you've customized your `plugins` list in
configuration, you'll need to explicitly add `musicbrainz` to continue
using MusicBrainz for autotagging.