Make sure sys._base_executable is sane in Vim plugin #1380
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #1379.
At least in Python 3.8, the
venvmodule relies onsys._base_executableto determine the Python executable to run, but with recent versions of Vim (8.2.654 from Homebrew on macOS), this attribute is set to the Vim executable instead of Python: running:python3 import sys; print(sys._base_executable)prints/usr/local/bin/vim. This makes the Black Vim plugin one-time setup (i.e. virtualenv creation and Black Python package installation) fail at the ensurepip stage (becausevim -Im ensurepip ...doesn't make any sense).A possible workaround is to just override the
sys._base_executableattribute, especially since the Black plugin already overridessys.executable(possibly for similar reasons?) anyway. This is what the present patch does.More generally though, is this intended behavior or a bug in recent versions of Python and/or Vim? I'm leaning towards a bug in Vim, since running
:python3 import sys; print(sys._base_executable)in Neovim correctly prints a Python path, even with Python 3.8. Just trying to figure out whether this should be reported somewhere else as well :)