Move PromptChoice to beets.util module

And update imports that have been raising the deprecation warning.
This commit is contained in:
Šarūnas Nejus 2025-11-30 08:11:22 +00:00
parent dd72704d3d
commit 05430f312c
No known key found for this signature in database
8 changed files with 23 additions and 26 deletions

View file

@ -39,7 +39,7 @@ def __getattr__(name: str):
__name__, __name__,
{ {
"TerminalImportSession": "beets.ui.commands.import_.session", "TerminalImportSession": "beets.ui.commands.import_.session",
"PromptChoice": "beets.ui.commands.import_.session", "PromptChoice": "beets.util",
}, },
name, name,
) )

View file

@ -1,10 +1,9 @@
from collections import Counter from collections import Counter
from itertools import chain from itertools import chain
from typing import Any, NamedTuple
from beets import autotag, config, importer, logging, plugins, ui from beets import autotag, config, importer, logging, plugins, ui
from beets.autotag import Recommendation from beets.autotag import Recommendation
from beets.util import displayable_path from beets.util import PromptChoice, displayable_path
from beets.util.units import human_bytes, human_seconds_short from beets.util.units import human_bytes, human_seconds_short
from .display import ( from .display import (
@ -368,12 +367,6 @@ def _summary_judgment(rec):
return action return action
class PromptChoice(NamedTuple):
short: str
long: str
callback: Any
def choose_candidate( def choose_candidate(
candidates, candidates,
singleton, singleton,

View file

@ -167,6 +167,12 @@ class MoveOperation(Enum):
REFLINK_AUTO = 5 REFLINK_AUTO = 5
class PromptChoice(NamedTuple):
short: str
long: str
callback: Any
def normpath(path: PathLike) -> bytes: def normpath(path: PathLike) -> bytes:
"""Provide the canonical form of the path suitable for storing in """Provide the canonical form of the path suitable for storing in
the database. the database.

View file

@ -25,8 +25,8 @@ import yaml
from beets import plugins, ui, util from beets import plugins, ui, util
from beets.dbcore import types from beets.dbcore import types
from beets.importer import Action from beets.importer import Action
from beets.ui.commands.import_.session import PromptChoice
from beets.ui.commands.utils import do_query from beets.ui.commands.utils import do_query
from beets.util import PromptChoice
# These "safe" types can avoid the format/parse cycle that most fields go # These "safe" types can avoid the format/parse cycle that most fields go
# through: they are safe to edit with native YAML types. # through: they are safe to edit with native YAML types.

View file

@ -26,8 +26,7 @@ import subprocess
from beets import ui from beets import ui
from beets.autotag import Recommendation from beets.autotag import Recommendation
from beets.plugins import BeetsPlugin from beets.plugins import BeetsPlugin
from beets.ui.commands import PromptChoice from beets.util import PromptChoice, displayable_path
from beets.util import displayable_path
from beetsplug.info import print_data from beetsplug.info import print_data

View file

@ -21,8 +21,7 @@ from os.path import relpath
from beets import config, ui, util from beets import config, ui, util
from beets.plugins import BeetsPlugin from beets.plugins import BeetsPlugin
from beets.ui import Subcommand from beets.ui import Subcommand
from beets.ui.commands import PromptChoice from beets.util import PromptChoice, get_temp_filename
from beets.util import get_temp_filename
# Indicate where arguments should be inserted into the command string. # Indicate where arguments should be inserted into the command string.
# If this is missing, they're placed at the end. # If this is missing, they're placed at the end.

View file

@ -13,7 +13,7 @@ shall expose to the user:
.. code-block:: python .. code-block:: python
from beets.plugins import BeetsPlugin from beets.plugins import BeetsPlugin
from beets.ui.commands import PromptChoice from beets.util import PromptChoice
class ExamplePlugin(BeetsPlugin): class ExamplePlugin(BeetsPlugin):

View file

@ -41,7 +41,7 @@ from beets.test.helper import (
PluginTestCase, PluginTestCase,
TerminalImportMixin, TerminalImportMixin,
) )
from beets.util import displayable_path, syspath from beets.util import PromptChoice, displayable_path, syspath
class TestPluginRegistration(PluginTestCase): class TestPluginRegistration(PluginTestCase):
@ -292,8 +292,8 @@ class PromptChoicesTest(TerminalImportMixin, PluginImportTestCase):
def return_choices(self, session, task): def return_choices(self, session, task):
return [ return [
ui.commands.PromptChoice("f", "Foo", None), PromptChoice("f", "Foo", None),
ui.commands.PromptChoice("r", "baR", None), PromptChoice("r", "baR", None),
] ]
self.register_plugin(DummyPlugin) self.register_plugin(DummyPlugin)
@ -328,8 +328,8 @@ class PromptChoicesTest(TerminalImportMixin, PluginImportTestCase):
def return_choices(self, session, task): def return_choices(self, session, task):
return [ return [
ui.commands.PromptChoice("f", "Foo", None), PromptChoice("f", "Foo", None),
ui.commands.PromptChoice("r", "baR", None), PromptChoice("r", "baR", None),
] ]
self.register_plugin(DummyPlugin) self.register_plugin(DummyPlugin)
@ -363,10 +363,10 @@ class PromptChoicesTest(TerminalImportMixin, PluginImportTestCase):
def return_choices(self, session, task): def return_choices(self, session, task):
return [ return [
ui.commands.PromptChoice("a", "A foo", None), # dupe PromptChoice("a", "A foo", None), # dupe
ui.commands.PromptChoice("z", "baZ", None), # ok PromptChoice("z", "baZ", None), # ok
ui.commands.PromptChoice("z", "Zupe", None), # dupe PromptChoice("z", "Zupe", None), # dupe
ui.commands.PromptChoice("z", "Zoo", None), PromptChoice("z", "Zoo", None),
] # dupe ] # dupe
self.register_plugin(DummyPlugin) self.register_plugin(DummyPlugin)
@ -399,7 +399,7 @@ class PromptChoicesTest(TerminalImportMixin, PluginImportTestCase):
) )
def return_choices(self, session, task): def return_choices(self, session, task):
return [ui.commands.PromptChoice("f", "Foo", self.foo)] return [PromptChoice("f", "Foo", self.foo)]
def foo(self, session, task): def foo(self, session, task):
pass pass
@ -441,7 +441,7 @@ class PromptChoicesTest(TerminalImportMixin, PluginImportTestCase):
) )
def return_choices(self, session, task): def return_choices(self, session, task):
return [ui.commands.PromptChoice("f", "Foo", self.foo)] return [PromptChoice("f", "Foo", self.foo)]
def foo(self, session, task): def foo(self, session, task):
return Action.SKIP return Action.SKIP