diff --git a/news/10716.feature.rst b/news/10716.feature.rst new file mode 100644 index 00000000000..ef09e1b8f58 --- /dev/null +++ b/news/10716.feature.rst @@ -0,0 +1 @@ +Use ``shell=True`` for opening the editor with ``pip config edit``. diff --git a/src/pip/_internal/commands/configuration.py b/src/pip/_internal/commands/configuration.py index e3837325986..84b134e490b 100644 --- a/src/pip/_internal/commands/configuration.py +++ b/src/pip/_internal/commands/configuration.py @@ -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