BUG: Wrong path edited when running config -e

Previously: ALWAYS edited the default config path
Corrected: When the --config <path> option is used, that path is edited
This commit is contained in:
Emi Katagiri-Simpson 2025-03-23 15:29:41 -04:00
parent 670a3bcd17
commit 4a43191c31
No known key found for this signature in database
4 changed files with 22 additions and 4 deletions

View file

@ -1839,7 +1839,7 @@ def _raw_main(args, lib=None):
): ):
from beets.ui.commands import config_edit from beets.ui.commands import config_edit
return config_edit() return config_edit(options)
test_lib = bool(lib) test_lib = bool(lib)
subcommands, plugins, lib = _setup(options, lib) subcommands, plugins, lib = _setup(options, lib)

View file

@ -2351,7 +2351,10 @@ def config_func(lib, opts, args):
# Open in editor. # Open in editor.
elif opts.edit: elif opts.edit:
config_edit() # Note: This branch *should* be unreachable
# since the normal flow should be short-circuited
# by the special case in ui._raw_main
config_edit(opts)
# Dump configuration. # Dump configuration.
else: else:
@ -2362,11 +2365,11 @@ def config_func(lib, opts, args):
print("Empty configuration") print("Empty configuration")
def config_edit(): def config_edit(cli_options):
"""Open a program to edit the user configuration. """Open a program to edit the user configuration.
An empty config file is created if no existing config file exists. An empty config file is created if no existing config file exists.
""" """
path = config.user_config_path() path = cli_options.config or config.user_config_path()
editor = util.editor_command() editor = util.editor_command()
try: try:
if not os.path.isfile(path): if not os.path.isfile(path):

View file

@ -49,6 +49,9 @@ Bug fixes:
* :ref:`query-sort`: Fix a bug that would raise an exception when sorting on * :ref:`query-sort`: Fix a bug that would raise an exception when sorting on
a non-string field that is not populated in all items. a non-string field that is not populated in all items.
:bug:`5512` :bug:`5512`
* Running `beet --config <mypath> config -e` now edits `<mypath>` rather than
the default config path.
:bug:`5652`
* :doc:`plugins/lastgenre`: Fix track-level genre handling. Now when an album-level * :doc:`plugins/lastgenre`: Fix track-level genre handling. Now when an album-level
genre is set already, single tracks don't fall back to the album's genre and genre is set already, single tracks don't fall back to the album's genre and
request their own last.fm genre. Also log messages regarding what's been request their own last.fm genre. Also log messages regarding what's been

View file

@ -128,3 +128,15 @@ class ConfigCommandTest(BeetsTestCase):
with patch("os.execlp") as execlp: with patch("os.execlp") as execlp:
self.run_command("config", "-e") self.run_command("config", "-e")
execlp.assert_called_once_with("myeditor", "myeditor", self.config_path) execlp.assert_called_once_with("myeditor", "myeditor", self.config_path)
def test_edit_config_with_custom_config_path(self):
alt_config_path = os.path.join(
self.temp_dir.decode(), "alt_config.yaml"
)
with open(self.config_path, "w") as file:
file.write("option: alt value\n")
os.environ["EDITOR"] = "myeditor"
with patch("os.execlp") as execlp:
self.run_command("--config", alt_config_path, "config", "-e")
execlp.assert_called_once_with("myeditor", "myeditor", alt_config_path)