mirror of https://github.com/dense-analysis/ale
Add auto_pipenv config for black
Added ability to set `python_black_auto_pipenv` to allow for usage of a local pipenv black executable.
This commit is contained in:
parent
73ca1e7191
commit
6619e1ac53
|
@ -4,22 +4,32 @@
|
||||||
call ale#Set('python_black_executable', 'black')
|
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_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||||
call ale#Set('python_black_options', '')
|
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
|
function! ale#fixers#black#Fix(buffer) abort
|
||||||
let l:executable = ale#python#FindExecutable(
|
let l:executable = ale#fixers#black#GetExecutable(a:buffer)
|
||||||
\ a:buffer,
|
|
||||||
\ 'python_black',
|
|
||||||
\ ['black'],
|
|
||||||
\)
|
|
||||||
|
|
||||||
if !executable(l:executable)
|
if !executable(l:executable)
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let l:exec_args = l:executable =~? 'pipenv$'
|
||||||
|
\ ? ' run black'
|
||||||
|
\ : ''
|
||||||
|
|
||||||
let l:options = ale#Var(a:buffer, 'python_black_options')
|
let l:options = ale#Var(a:buffer, 'python_black_options')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#Escape(l:executable)
|
\ 'command': ale#Escape(l:executable) . l:exec_args
|
||||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||||
\ . ' -',
|
\ . ' -',
|
||||||
\}
|
\}
|
||||||
|
|
Loading…
Reference in New Issue