Skip to content

Commit 29b9958

Browse files
BUG: Wrong path edited when running config -e (#5685)
As per #5652, `beet --config <path> config -e` edited the default config path, even though that's not the config that would be used by beets. It seems like this was the result of a deliberate short-circuit in [`_raw_main()`](https://github.com/Alch-Emi/beets/blob/c2de6feada5c84d8bd0235969d551b6a4fce1277/beets/ui/__init__.py#L1832). The short-circuit prevents malformed configs from causing a crash before opening the editor, but also prevents the setup function from loading the custom config at all. The solution used here is to just expose the CLI options to `edit_config()`, so that it can use the custom config path if its set. I also suspect that the branch in [`config_func()`](https://github.com/Alch-Emi/beets/blob/c2de6feada5c84d8bd0235969d551b6a4fce1277/beets/ui/commands.py#L2354) which is getting short circuited is actually unreachable, but I left it in with a note just in case. Fixes #5652 ## To Do - [x] ~~Documentation~~ (N/A) - [X] Changelog - [X] Tests
2 parents 7cca07d + 81f1072 commit 29b9958

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

beets/ui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ def parse_csl_callback(
16011601
):
16021602
from beets.ui.commands.config import config_edit
16031603

1604-
return config_edit()
1604+
return config_edit(options)
16051605

16061606
test_lib = bool(lib)
16071607
subcommands, lib = _setup(options, lib)

beets/ui/commands/config.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ def config_func(lib, opts, args):
3030

3131
# Open in editor.
3232
elif opts.edit:
33-
config_edit()
33+
# Note: This branch *should* be unreachable
34+
# since the normal flow should be short-circuited
35+
# by the special case in ui._raw_main
36+
config_edit(opts)
3437

3538
# Dump configuration.
3639
else:
@@ -41,11 +44,11 @@ def config_func(lib, opts, args):
4144
print("Empty configuration")
4245

4346

44-
def config_edit():
47+
def config_edit(cli_options):
4548
"""Open a program to edit the user configuration.
4649
An empty config file is created if no existing config file exists.
4750
"""
48-
path = config.user_config_path()
51+
path = cli_options.config or config.user_config_path()
4952
editor = editor_command()
5053
try:
5154
if not os.path.isfile(path):

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Bug fixes:
2929
audio-features endpoint, the plugin logs a warning once and skips audio
3030
features for all remaining tracks in the session, avoiding unnecessary API
3131
calls and rate limit exhaustion.
32+
- Running `beet --config <mypath> config -e` now edits `<mypath>` rather than
33+
the default config path. :bug:`5652`
3234
- :doc:`plugins/lyrics`: Accepts strings for lyrics sources (previously only
3335
accepted a list of strings). :bug:`5962`
3436

test/ui/commands/test_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,11 @@ def test_edit_invalid_config_file(self):
128128
with patch("os.execlp") as execlp:
129129
self.run_command("config", "-e")
130130
execlp.assert_called_once_with("myeditor", "myeditor", self.config_path)
131+
132+
def test_edit_config_with_custom_config_path(self):
133+
os.environ["EDITOR"] = "myeditor"
134+
with patch("os.execlp") as execlp:
135+
self.run_command("--config", self.cli_config_path, "config", "-e")
136+
execlp.assert_called_once_with(
137+
"myeditor", "myeditor", self.cli_config_path
138+
)

0 commit comments

Comments
 (0)