summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHoracio Sanson <hsanson@gmail.com>2021-10-16 14:02:58 +0900
committerGitHub <noreply@github.com>2021-10-16 14:02:58 +0900
commit16898417e68ffb6034b2a6de0c1b25502bd846d8 (patch)
treefcf7d1a64cb923135bf457b29362a626a9a9f3c7
parentc7e3f1a0dd447eeafcbbd158974860c1918dbdd5 (diff)
downloadale-16898417e68ffb6034b2a6de0c1b25502bd846d8.zip
Fix 3941 - add version check to isort fixer (#3942)
-rw-r--r--autoload/ale/fixers/isort.vim31
-rw-r--r--test/fixers/test_isort_fixer_callback.vader39
2 files changed, 55 insertions, 15 deletions
diff --git a/autoload/ale/fixers/isort.vim b/autoload/ale/fixers/isort.vim
index 082e77ec..6eb6a67c 100644
--- a/autoload/ale/fixers/isort.vim
+++ b/autoload/ale/fixers/isort.vim
@@ -21,7 +21,18 @@ function! ale#fixers#isort#GetExecutable(buffer) abort
return ale#python#FindExecutable(a:buffer, 'python_isort', ['isort'])
endfunction
-function! ale#fixers#isort#Fix(buffer) abort
+function! ale#fixers#isort#GetCmd(buffer) abort
+ let l:executable = ale#fixers#isort#GetExecutable(a:buffer)
+ let l:cmd = [ale#Escape(l:executable)]
+
+ if l:executable =~? 'pipenv\|poetry$'
+ call extend(l:cmd, ['run', 'isort'])
+ endif
+
+ return join(l:cmd, ' ')
+endfunction
+
+function! ale#fixers#isort#FixForVersion(buffer, version) abort
let l:executable = ale#fixers#isort#GetExecutable(a:buffer)
let l:cmd = [ale#Escape(l:executable)]
@@ -29,7 +40,9 @@ function! ale#fixers#isort#Fix(buffer) abort
call extend(l:cmd, ['run', 'isort'])
endif
- call add(l:cmd, '--filename %s')
+ if ale#semver#GTE(a:version, [5, 7, 0])
+ call add(l:cmd, '--filename %s')
+ endif
let l:options = ale#Var(a:buffer, 'python_isort_options')
@@ -41,6 +54,18 @@ function! ale#fixers#isort#Fix(buffer) abort
return {
\ 'cwd': '%s:h',
- \ 'command': join(l:cmd, ' ')
+ \ 'command': join(l:cmd, ' '),
\}
endfunction
+
+function! ale#fixers#isort#Fix(buffer) abort
+ let l:executable = ale#fixers#isort#GetExecutable(a:buffer)
+ let l:command = ale#fixers#isort#GetCmd(a:buffer) . ale#Pad('--version')
+
+ return ale#semver#RunWithVersionCheck(
+ \ a:buffer,
+ \ l:executable,
+ \ l:command,
+ \ function('ale#fixers#isort#FixForVersion'),
+ \)
+endfunction
diff --git a/test/fixers/test_isort_fixer_callback.vader b/test/fixers/test_isort_fixer_callback.vader
index 72882737..8b665d6b 100644
--- a/test/fixers/test_isort_fixer_callback.vader
+++ b/test/fixers/test_isort_fixer_callback.vader
@@ -11,45 +11,60 @@ After:
Execute(The isort callback should return the correct default values):
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
- AssertEqual
+
+ " --filename option exists only after 5.7.0
+ GivenCommandOutput ['VERSION 5.7.0']
+ AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/isort')) . ' --filename %s' . ' -',
- \ },
- \ ale#fixers#isort#Fix(bufnr(''))
+ \ }
Execute(The isort callback should respect custom options):
let g:ale_python_isort_options = '--multi-line=3 --trailing-comma'
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
- AssertEqual
+
+ " --filename option exists only after 5.7.0
+ GivenCommandOutput ['VERSION 5.7.0']
+ AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/isort'))
\ . ' --filename %s' . ' --multi-line=3 --trailing-comma -',
- \ },
- \ ale#fixers#isort#Fix(bufnr(''))
+ \ }
Execute(Pipenv is detected when python_isort_auto_pipenv is set):
let g:ale_python_isort_auto_pipenv = 1
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
- AssertEqual
+ GivenCommandOutput ['VERSION 5.7.0']
+ AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape('pipenv') . ' run isort' . ' --filename %s' . ' -'
- \ },
- \ 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
+ GivenCommandOutput ['VERSION 5.7.0']
+ AssertFixer
\ {
\ 'cwd': '%s:h',
\ 'command': ale#Escape('poetry') . ' run isort' . ' --filename %s' . ' -'
- \ },
- \ ale#fixers#isort#Fix(bufnr(''))
+ \ }
+
+Execute(The isort callback should not use --filename for older versions):
+ silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_virtualenv/subdir/foo/bar.py')
+
+ " --filename option exists only after 5.7.0
+ GivenCommandOutput ['VERSION 5.6.0']
+ AssertFixer
+ \ {
+ \ 'cwd': '%s:h',
+ \ 'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/isort')) . ' -',
+ \ }