Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68a3c75

Browse files
authored
Make sure sys._base_executable is sane in Vim plugin (psf#1380)
The `venv` module relies on `sys._base_executable` to determine the Python executable to run, but with recent versions of Vim, this is set to the `vim` executable. A possible workaround is to just override it, since the `black` plugin already overrides `sys.executable` (possibly for similar reasons?) anyway.
1 parent 1d3fb87 commit 68a3c75

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

plugin/black.vim

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,23 @@ def _initialize_black_env(upgrade=False):
110110
if not virtualenv_path.is_dir():
111111
print('Please wait, one time setup for Black.')
112112
_executable = sys.executable
113+
_base_executable = getattr(sys, "_base_executable", _executable)
113114
try:
114-
sys.executable = str(_get_python_binary(Path(sys.exec_prefix)))
115+
executable = str(_get_python_binary(Path(sys.exec_prefix)))
116+
sys.executable = executable
117+
sys._base_executable = executable
115118
print(f'Creating a virtualenv in {virtualenv_path}...')
116119
print('(this path can be customized in .vimrc by setting g:black_virtualenv)')
117120
venv.create(virtualenv_path, with_pip=True)
121+
except Exception:
122+
print('Encountered exception while creating virtualenv (see traceback below).')
123+
print(f'Removing {virtualenv_path}...')
124+
import shutil
125+
shutil.rmtree(virtualenv_path)
126+
raise
118127
finally:
119128
sys.executable = _executable
129+
sys._base_executable = _base_executable
120130
first_install = True
121131
if first_install:
122132
print('Installing Black with pip...')

0 commit comments

Comments
 (0)