Skip to content

Commit

Permalink
Merge pull request #10716 from pradyunsg/better-editor-handling
Browse files Browse the repository at this point in the history
Improve how editors are handled in `pip config`
  • Loading branch information
pradyunsg authored Jul 29, 2022
2 parents 0755d5c + 89983e9 commit 4fd08e1
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 4fd08e1

Please sign in to comment.