From 89983e9ad923826217cf06f30f7c52f36c1b6069 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Wed, 8 Dec 2021 18:44:11 +0000 Subject: [PATCH] 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. --- news/10716.feature.rst | 1 + src/pip/_internal/commands/configuration.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 news/10716.feature.rst 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