From 6619e1ac53143dd4f09223c9414e1159852aaf31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miklo=CC=81s=20Tusz?= Date: Wed, 10 Oct 2018 09:04:20 -0400 Subject: [PATCH] Add auto_pipenv config for black Added ability to set `python_black_auto_pipenv` to allow for usage of a local pipenv black executable. --- autoload/ale/fixers/black.vim | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/autoload/ale/fixers/black.vim b/autoload/ale/fixers/black.vim index 4169322a..7523bcae 100644 --- a/autoload/ale/fixers/black.vim +++ b/autoload/ale/fixers/black.vim @@ -4,22 +4,32 @@ call ale#Set('python_black_executable', 'black') call ale#Set('python_black_use_global', get(g:, 'ale_use_global_executables', 0)) call ale#Set('python_black_options', '') +call ale#Set('python_black_auto_pipenv', 0) + +function! ale#fixers#black#GetExecutable(buffer) abort + if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_black_auto_pipenv')) + \ && ale#python#PipenvPresent(a:buffer) + return 'pipenv' + endif + + return ale#python#FindExecutable(a:buffer, 'python_black', ['black']) +endfunction function! ale#fixers#black#Fix(buffer) abort - let l:executable = ale#python#FindExecutable( - \ a:buffer, - \ 'python_black', - \ ['black'], - \) + let l:executable = ale#fixers#black#GetExecutable(a:buffer) if !executable(l:executable) return 0 endif + let l:exec_args = l:executable =~? 'pipenv$' + \ ? ' run black' + \ : '' + let l:options = ale#Var(a:buffer, 'python_black_options') return { - \ 'command': ale#Escape(l:executable) + \ 'command': ale#Escape(l:executable) . l:exec_args \ . (!empty(l:options) ? ' ' . l:options : '') \ . ' -', \}