black: vim plugin way of installing black is broken

Describe the bug

The way the vim plugin install black is broken because:

  • it does not guarantee the installed black will actually be used as it is added at the end of sys.path so any other version on the system will be used instead
  • it install the latest version of black registered on pypi which can be incompatible with the vim plugin itself, in particular when following the installation instructions as Plug will install from master

To Reproduce Steps to reproduce the behavior:

  1. Add Plug 'psf/black' to your vimrc
  2. Run vim -c PlugInstall
  3. Run vim foo.py -c Black
  4. See error:
"foo.py" [New File]
Error detected while processing command line:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 97, in Black
  File "<string>", line 133, in get_configs
AttributeError: module 'black' has no attribute 'find_pyproject_toml'

Expected behavior

No error and vim ready to edit the file.

Environment (please complete the following information):

  • Version: master
  • OS and Python version: Linux/Python 3.7.5

Additional context

Somewhat related issue about the forced installation of black by the vim plugin: #1269

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 30
  • Comments: 22 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Using Plug:

Plug 'psf/black', { 'commit': 'ce14fa8b497bae2b50ec48b3bd7022573a59cdb1' }

Thanks to @bkjohnson for showing how to pin vim-black to the installed release from pypi using vim-plug:

Plug 'psf/black', { 'tag': '19.10b0' }

For anyone interested, until this bug is fixed using commit ce14fa8b497bae2b50ec48b3bd7022573a59cdb1 works fine, as the commit 8fef74cf527d7fa5f2da78fafc61152c8766d0ad is the one which introduces ‘find_pyproject_toml’ function.

For example using dein

call dein#add('psf/black', { 'rev': 'ce14fa8b497bae2b50ec48b3bd7022573a59cdb1' })

I have to provide a branch to make it work.

Plug 'psf/black', { 'branch': 'stable' }

I think this can now be closed (cf. #1318).

Thanks @PanagiotisS! I had a couple issues

  • ~/.local/share/nvim/black was linked to a blob, likely an issue on my end trying to install the blob of black.vim instead of the repo
  • nvim wasn’t finding python :echo has('python3') would always net 0

Cleaning out the plugin dir and resintalling as well as installing pynvim seemed to get it to work!

@richtong check out my fork https://github.com/EgZvor/vim-black it uses the executable available in the system and supports ranges.

Oh, is #1318 ALSO the fix for 1379? Indeed, indeed it is!