Describe the bug
The way the vim plugin install black is broken because:
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 insteadPlug will install from masterTo Reproduce Steps to reproduce the behavior:
Plug 'psf/black' to your vimrcvim -c PlugInstallvim foo.py -c Black"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):
Additional context
Somewhat related issue about the forced installation of black by the vim plugin: #1269
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' })
Using Plug:
Plug 'psf/black', { 'commit': 'ce14fa8b497bae2b50ec48b3bd7022573a59cdb1' }
Probably related? I got the following error when upgrading. Maybe important fact: installed from an activated venv. (:grey_question: )
~
subprocess.CalledProcessError: Command '['/home/leblancfg/.vim/black/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' died with
~
Using @PanagiotisS' fix made it work.
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' }
I think this can now be closed (cf. #1318).
I hit this issue this morning (June 3 2020), what closes this?
Ah I see. #1318 solves the problem for new vim installations (ie after modifying vimrc, reinstalling black, running the console command), got it. Thanks!
It's the change in the docs that I referenced above. To avoid this issue, you must take particular precautions when installing psf/black.
Yep :) 🎉
Got it thanks. I hit this issue as well as https://github.com/psf/black/issues/1379 this morning which seems closed however only executing the very last comment there fixes it for me, so not sure why that was closed.
Oh, is #1318 ALSO the fix for 1379? Indeed, indeed it is!
I have to provide a branch to make it work.
Plug 'psf/black', { 'branch': 'stable' }
I'm suddenly getting this black error again even with the branch stable fix. Any ideas? I have externally brew install black so the command line I have version 20.8.b1_1
So is table no longer the correct pinning needed? I tried the {'tag': '19.10b0'} and this fails with
File <string>, line 63, in <module>
ModuleNotFoundError: No module named 'black'
@richtong check out my fork https://github.com/EgZvor/vim-black it uses the executable available in the system and supports ranges.
@richtong The plugin unfortunately doesn't have a good health check story while at the same time being fairly brittle (the virtualenv can break, the versions can get out of sync). I've found it easiest to just delete the virtualenv and start afresh when I run into trouble. I even added a command for that so that I don't have to remember the particulars:
function! s:black_reinstall()
" if using vim-plug: make sure the black plugin is loaded
call plug#load('black')
echom "BlackReinstall: Removing Black's virtualenv in ".g:black_virtualenv.'.'
echom repeat('=', 72)
python3 import os, shutil, vim; shutil.rmtree(os.path.expanduser(vim.eval("g:black_virtualenv")))
BlackUpgrade
echom repeat('=', 72)
" again, the :PlugUpdate recommendation applies if using vim-plug
echom 'BlackReinstall: If the issue persists, run :PlugUpdate black and retry reinstalling.'
endfunction
command! BlackReinstall :call s:black_reinstall()
@EgZvor may be onto something with his fork -- separating out the plugin and relying on the user to install black manually will probably make it easier to troubleshoot, not to mention more lightweight.
@richtong check out my fork https://github.com/EgZvor/vim-black it uses the executable available in the system and supports ranges.
@EgZvor Thank you! I've been really frustrated by this bug and the addition of ranges is great.
Wow. This is a great idea. The reinstall.
Sent via Superhuman iOS ( https://sprh.mn/[email protected] )
On Fri, Oct 23 2020 at 13:42, Fred Bunt < [email protected] > wrote:
@richtong ( https://github.com/richtong ) check out my fork https://github.com/EgZvor/vim-black
it uses the executable available in the system and supports ranges.@EgZvor ( https://github.com/EgZvor ) Thank you! I've been really
frustrated by this bug and the addition of ranges is great.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (
https://github.com/psf/black/issues/1304#issuecomment-715580129 ) , or unsubscribe
(
https://github.com/notifications/unsubscribe-auth/AANTCRYKP22SSJQ2SNUASP3SMHTCTANCNFSM4LFRRKMA
).
And having black installed outside makes sense. It’s the way syntactic works.
Sent via Superhuman iOS ( https://sprh.mn/[email protected] )
On Wed, Oct 28 2020 at 14:43, < [email protected] > wrote:
Wow. This is a great idea. The reinstall.
Sent via Superhuman iOS ( https://sprh.mn/[email protected] )
On Fri, Oct 23 2020 at 13:42, Fred Bunt < [email protected] > wrote:
@richtong ( https://github.com/richtong ) check out my fork https://github.com/EgZvor/vim-black
it uses the executable available in the system and supports ranges.@EgZvor ( https://github.com/EgZvor ) Thank you! I've been really
frustrated by this bug and the addition of ranges is great.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (
https://github.com/psf/black/issues/1304#issuecomment-715580129 ) , or unsubscribe
(
https://github.com/notifications/unsubscribe-auth/AANTCRYKP22SSJQ2SNUASP3SMHTCTANCNFSM4LFRRKMA
).
@PanagiotisS does the dein install actually work for you?
When I used that and run :call dein@install() vim can't find the :Black command
@PanagiotisS does the dein install actually work for you?
When I used that and run:call dein@install()vim can't find the:Blackcommand
Hi @Chocrates,
As it was frequently broken, I had actually given up on using it as a plugin and instead I was using :!black %.
So, I just made a minimal vimrc with just dein and black call dein#add('psf/black', { 'rev': 'stable' }) and dein reports
[dein] /home/ps/.local/share/nvim/dein/repos/github.com/psf/black_stable
[dein] fatal: invalid reference: stable
And it just installs the master branch (dein bug?)
± pwd
/home/ps/.local/share/nvim/dein/repos/github.com/psf/black_stable
± git status
# On branch master
Suprisingly at the moment of writting it works.
It initialised and subsequently I can run it with :Black
:BlackVersion
Black, version 20.8b1 on Python 3.8.0 | packaged by conda-forge | (default, Nov 22 2019, 19:11:38)
[GCC 7.3.0].
or outside conda env where I do not have black installed
:BlackVersion
Black, version 20.8b1 on Python 3.6.8 (default, Apr 2 2020, 13:34:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)].
````
If I instead use the revision from my previous post,
```vim
call dein#add('psf/black', { 'rev': 'ce14fa8b497bae2b50ec48b3bd7022573a59cdb1' })
it installs the requested revision
± pwd
/home/ps/.local/share/nvim/dein/repos/github.com/psf/black_ce14fa8b497bae2b50ec48b3bd7022573a59cdb1
± git status
# HEAD detached at ce14fa8
and works without problems again
:BlackVersion
Black, version 20.8b1 on Python 3.8.0 | packaged by conda-forge | (default, Nov 22 2019, 19:11:38)
[GCC 7.3.0].
I am using self-built neovim https://github.com/neovim/neovim/commit/71d4f5851f068eeb432af34850dddda8cc1c71e3
As vim cannot find black, most likely is not installed correctly? (Check if the directories are there, the runtimepath has no issues).
Also, I think deleting the black directory ~/.local/share/nvim/black can help with some problems.
The commands dein#recache_runtimepath() and dein#clear_state() are useful (or manually delete the respective directory and file).
I rarely use Windows so I cannot help you if there are any Windows specific issues.
Edit: Just in case it is not a typo, the command should be :call dein#install() or :call dein#update().
Thanks @PanagiotisS! I had a couple issues
:echo has('python3') would always net 0Cleaning out the plugin dir and resintalling as well as installing pynvim seemed to get it to work!
Most helpful comment
Using Plug: