Fix 3897 - add poetry to isort (#3898)

Co-authored-by: Horacio Sanson <horacio@allm.inc>
This commit is contained in:
Horacio Sanson
2021-09-10 15:18:41 +09:00
committed by GitHub
parent b504eeb094
commit bf29f6ea92
3 changed files with 41 additions and 17 deletions

View File

@@ -5,6 +5,7 @@ call ale#Set('python_isort_executable', 'isort')
call ale#Set('python_isort_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('python_isort_options', '')
call ale#Set('python_isort_auto_pipenv', 0)
call ale#Set('python_isort_auto_poetry', 0)
function! ale#fixers#isort#GetExecutable(buffer) abort
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_isort_auto_pipenv'))
@@ -12,24 +13,34 @@ function! ale#fixers#isort#GetExecutable(buffer) abort
return 'pipenv'
endif
if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_isort_auto_poetry'))
\ && ale#python#PoetryPresent(a:buffer)
return 'poetry'
endif
return ale#python#FindExecutable(a:buffer, 'python_isort', ['isort'])
endfunction
function! ale#fixers#isort#Fix(buffer) abort
let l:options = ale#Var(a:buffer, 'python_isort_options')
let l:executable = ale#fixers#isort#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv$'
\ ? ' run isort'
\ : ''
let l:cmd = [ale#Escape(l:executable)]
if !executable(l:executable) && l:executable isnot# 'pipenv'
return 0
if l:executable =~? 'pipenv\|poetry$'
call extend(l:cmd, ['run', 'isort'])
endif
call add(l:cmd, '--filename %s')
let l:options = ale#Var(a:buffer, 'python_isort_options')
if !empty(l:options)
call add(l:cmd, l:options)
endif
call add(l:cmd, '-')
return {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(l:executable) . l:exec_args
\ . ale#Pad('--filename %s')
\ . (!empty(l:options) ? ' ' . l:options : '') . ' -',
\ 'command': join(l:cmd, ' ')
\}
endfunction