diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index 668c999010..9dcdbbadc8 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -9,6 +9,7 @@ from __future__ import annotations +import logging import os import re from collections import defaultdict @@ -717,7 +718,11 @@ def _fetch_and_log_genre(self, obj: LibModel) -> None: obj.genres, label = self._get_genre(obj) self._log.debug("Resolved ({}): {}", label, obj.genres) - ui.show_model_changes(obj, fields=["genres"], print_obj=False) + # Only print the changes if INFO logs are enabled. That is the case when + # running the command, but not during an import (unless it is verbose), + # where printed output can appear on top of the importer's prompt. + if self._log.isEnabledFor(logging.INFO): + ui.show_model_changes(obj, fields=["genres"], print_obj=False) @singledispatchmethod def _process(self, obj: LibModel, write: bool) -> None: diff --git a/docs/changelog.rst b/docs/changelog.rst index d21f25191f..9002a3a986 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -139,6 +139,10 @@ Bug fixes ``Hybrid SACD (SACD layer, 2 channels)``) or the sides of a DualDisc, the album's ``media`` is now their common format (``Hybrid SACD``) instead of the generic ``Media``. Releases mixing different formats still get ``Media``. +- :doc:`plugins/lastgenre`: The genre changes are no longer printed during an + import (unless it is verbose), where they could appear on top of the + importer's prompt for the next album and make the import look frozen. The + ``lastgenre`` command still prints them. :bug:`6830` For plugin developers ~~~~~~~~~~~~~~~~~~~~~ diff --git a/test/plugins/test_lastgenre.py b/test/plugins/test_lastgenre.py index d383480ddc..e2d01ec7bb 100644 --- a/test/plugins/test_lastgenre.py +++ b/test/plugins/test_lastgenre.py @@ -160,6 +160,48 @@ def unexpected_store(*_, **__): assert album.genres == ["Original Genre"] assert album.items()[0].genres == ["Original Genre"] + def _add_album_for_import(self) -> Album: + item = self.create_item( + album="Import Album", + albumartist="Import Artist", + artist="Import Artist", + title="Import Track", + ) + return self.lib.add_album([item]) + + def _run_import_stage(self, album): + """Run the import stage as the importer does, return what it printed.""" + task = Mock(is_album=True, album=album) + self.io.getoutput() + + with patch.object( + self.plugin, "_get_genre", return_value=(["Rock"], "test") + ): + for stage in self.plugin.get_import_stages(): + stage(Mock(), task) + + return self.io.getoutput() + + def test_import_stage_does_not_print_genre_changes(self): + """The import stage must not print by default. + + See #6830: the printed genre changes appeared on top of the importer's + prompt for the next album, which made the import look frozen. + """ + self.config["verbose"] = 0 + album = self._add_album_for_import() + + assert self._run_import_stage(album) == "" + + album.load() + assert album.genres == ["Rock"] + + def test_import_stage_prints_genre_changes_when_verbose(self): + self.config["verbose"] = 1 + album = self._add_album_for_import() + + assert "genres:" in self._run_import_stage(album) + def test_no_duplicate(self): """Remove duplicated genres.""" self._setup_config(count=99)