Skip to content

Commit 89983e9

Browse files
committed
Use shell=True for opening the editor with pip config edit
This makes the behavior compatible with git and other tools that invoke the editor in this manner.
1 parent b8ccb04 commit 89983e9

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

news/10716.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use ``shell=True`` for opening the editor with ``pip config edit``.

src/pip/_internal/commands/configuration.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,15 @@ def open_in_editor(self, options: Values, args: List[str]) -> None:
228228
fname = self.configuration.get_file_to_edit()
229229
if fname is None:
230230
raise PipError("Could not determine appropriate file.")
231+
elif '"' in fname:
232+
# This shouldn't happen, unless we see a username like that.
233+
# If that happens, we'd appreciate a pull request fixing this.
234+
raise PipError(
235+
f'Can not open an editor for a file name containing "\n{fname}'
236+
)
231237

232238
try:
233-
subprocess.check_call([editor, fname])
239+
subprocess.check_call(f'{editor} "{fname}"', shell=True)
234240
except FileNotFoundError as e:
235241
if not e.filename:
236242
e.filename = editor

0 commit comments

Comments
 (0)