Skip to content

Commit

Permalink
Use shell=True for opening the editor with pip config edit
Browse files Browse the repository at this point in the history
This makes the behavior compatible with git and other tools that invoke
the editor in this manner.
  • Loading branch information
pradyunsg committed Jul 29, 2022
1 parent b8ccb04 commit 89983e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/10716.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use ``shell=True`` for opening the editor with ``pip config edit``.
8 changes: 7 additions & 1 deletion src/pip/_internal/commands/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,15 @@ def open_in_editor(self, options: Values, args: List[str]) -> None:
fname = self.configuration.get_file_to_edit()
if fname is None:
raise PipError("Could not determine appropriate file.")
elif '"' in fname:
# This shouldn't happen, unless we see a username like that.
# If that happens, we'd appreciate a pull request fixing this.
raise PipError(
f'Can not open an editor for a file name containing "\n{fname}'
)

try:
subprocess.check_call([editor, fname])
subprocess.check_call(f'{editor} "{fname}"', shell=True)
except FileNotFoundError as e:
if not e.filename:
e.filename = editor
Expand Down

0 comments on commit 89983e9

Please sign in to comment.