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.
Currently this message shows up with no context prior to the start of
Vim. By changing this to a lazy message, the user will only be notified
of a problem with the Black plugin when they are attempting to use the
Black plugin.
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Creates two separate functions:
1) abspath_pyproject_toml: find the absolute path to pyproject.toml
2) parse_pyproject_toml: finds black-specific toml config
Co-authored-by: Samuel Roeca <samuel.roeca@gmail.com>
If we have the same buffer open in multiple windows/tabs, we'll only
restore the current window's cursor.
Iterate through all tabs and windows, and save/restore all cursor
positions of windows that contain our buffer.
Addendum to #433.
- Check if black venv path is not already in `sys.path`
- Append (not insert) path so that black doesn't incorrectly import backports (e.g. `typing`)
Avoids this error if `typing` is present in venv:
```
Traceback (most recent call last):
File "<string>", line 56, in <module>
File "/home/josh/.virtualenvs/default/lib/python3.7/site-packages/black.py", line 19, in <module>
from typing import (
File "/home/josh/.virtualenvs/default/lib/python3.7/site-packages/typing.py", line 1356, in <module>
class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
File "/home/josh/.virtualenvs/default/lib/python3.7/site-packages/typing.py", line 1004, in __new__
self._abc_registry = extra._abc_registry
AttributeError: type object 'Callable' has no attribute '_abc_registry'
```
Since 18.6b0 was released, there has been a new option to skip string
normalization when Black is called, but it wasn't able to be specified
from within the vim plugin. This commit adds that functionality.
Tested with g:black_skip_string_normalization set to 0 (off) and 1 (on).
Neovim uses stdout for `msgpack` communication and the `subprocess` call for `virtualenv` was leaking that stream. Fix is to attach to a `subprocess.PIPE`.