mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-08 05:24:46 +08:00
Fix 3897 - add poetry to isort (#3898)
Co-authored-by: Horacio Sanson <horacio@allm.inc>
This commit is contained in:
@@ -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_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||||
call ale#Set('python_isort_options', '')
|
call ale#Set('python_isort_options', '')
|
||||||
call ale#Set('python_isort_auto_pipenv', 0)
|
call ale#Set('python_isort_auto_pipenv', 0)
|
||||||
|
call ale#Set('python_isort_auto_poetry', 0)
|
||||||
|
|
||||||
function! ale#fixers#isort#GetExecutable(buffer) abort
|
function! ale#fixers#isort#GetExecutable(buffer) abort
|
||||||
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_isort_auto_pipenv'))
|
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'
|
return 'pipenv'
|
||||||
endif
|
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'])
|
return ale#python#FindExecutable(a:buffer, 'python_isort', ['isort'])
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#fixers#isort#Fix(buffer) abort
|
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:executable = ale#fixers#isort#GetExecutable(a:buffer)
|
||||||
let l:exec_args = l:executable =~? 'pipenv$'
|
let l:cmd = [ale#Escape(l:executable)]
|
||||||
\ ? ' run isort'
|
|
||||||
\ : ''
|
|
||||||
|
|
||||||
if !executable(l:executable) && l:executable isnot# 'pipenv'
|
if l:executable =~? 'pipenv\|poetry$'
|
||||||
return 0
|
call extend(l:cmd, ['run', 'isort'])
|
||||||
endif
|
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 {
|
return {
|
||||||
\ 'cwd': '%s:h',
|
\ 'cwd': '%s:h',
|
||||||
\ 'command': ale#Escape(l:executable) . l:exec_args
|
\ 'command': join(l:cmd, ' ')
|
||||||
\ . ale#Pad('--filename %s')
|
|
||||||
\ . (!empty(l:options) ? ' ' . l:options : '') . ' -',
|
|
||||||
\}
|
\}
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -356,6 +356,15 @@ g:ale_python_isort_auto_pipenv *g:ale_python_isort_auto_pipenv*
|
|||||||
if true. This is overridden by a manually-set executable.
|
if true. This is overridden by a manually-set executable.
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_python_isort_auto_poetry *g:ale_python_isort_auto_poetry*
|
||||||
|
*b:ale_python_isort_auto_poetry*
|
||||||
|
Type: |Number|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
|
Detect whether the file is inside a poetry, and set the executable to `poetry`
|
||||||
|
if true. This is overridden by a manually-set executable.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
mypy *ale-python-mypy*
|
mypy *ale-python-mypy*
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,6 @@ After:
|
|||||||
unlet! b:bin_dir
|
unlet! b:bin_dir
|
||||||
|
|
||||||
Execute(The isort callback should return the correct default values):
|
Execute(The isort callback should return the correct default values):
|
||||||
AssertEqual
|
|
||||||
\ 0,
|
|
||||||
\ ale#fixers#isort#Fix(bufnr(''))
|
|
||||||
|
|
||||||
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
@@ -25,10 +21,6 @@ Execute(The isort callback should return the correct default values):
|
|||||||
Execute(The isort callback should respect custom options):
|
Execute(The isort callback should respect custom options):
|
||||||
let g:ale_python_isort_options = '--multi-line=3 --trailing-comma'
|
let g:ale_python_isort_options = '--multi-line=3 --trailing-comma'
|
||||||
|
|
||||||
AssertEqual
|
|
||||||
\ 0,
|
|
||||||
\ ale#fixers#isort#Fix(bufnr(''))
|
|
||||||
|
|
||||||
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
@@ -49,3 +41,15 @@ Execute(Pipenv is detected when python_isort_auto_pipenv is set):
|
|||||||
\ 'command': ale#Escape('pipenv') . ' run isort' . ' --filename %s' . ' -'
|
\ 'command': ale#Escape('pipenv') . ' run isort' . ' --filename %s' . ' -'
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#isort#Fix(bufnr(''))
|
\ ale#fixers#isort#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(Poetry is detected when python_isort_auto_poetry is set):
|
||||||
|
let g:ale_python_isort_auto_poetry = 1
|
||||||
|
|
||||||
|
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'cwd': '%s:h',
|
||||||
|
\ 'command': ale#Escape('poetry') . ' run isort' . ' --filename %s' . ' -'
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#isort#Fix(bufnr(''))
|
||||||
|
|||||||
Reference in New Issue
Block a user