diff options
Diffstat (limited to 'ale_linters/python')
-rw-r--r-- | ale_linters/python/flake8.vim | 18 | ||||
-rw-r--r-- | ale_linters/python/mypy.vim | 16 | ||||
-rw-r--r-- | ale_linters/python/pydocstyle.vim | 4 | ||||
-rw-r--r-- | ale_linters/python/pylama.vim | 17 | ||||
-rw-r--r-- | ale_linters/python/pylint.vim | 18 | ||||
-rw-r--r-- | ale_linters/python/vulture.vim | 19 |
6 files changed, 42 insertions, 50 deletions
diff --git a/ale_linters/python/flake8.vim b/ale_linters/python/flake8.vim index fc4ab692..1d49d03f 100644 --- a/ale_linters/python/flake8.vim +++ b/ale_linters/python/flake8.vim @@ -38,30 +38,28 @@ function! ale_linters#python#flake8#RunWithVersionCheck(buffer) abort \) endfunction -function! ale_linters#python#flake8#GetCdString(buffer) abort +function! ale_linters#python#flake8#GetCwd(buffer) abort let l:change_directory = ale#Var(a:buffer, 'python_flake8_change_directory') - let l:cd_string = '' + let l:cwd = '' if l:change_directory is# 'project' let l:project_root = ale#python#FindProjectRootIni(a:buffer) if !empty(l:project_root) - let l:cd_string = ale#path#CdString(l:project_root) + let l:cwd = l:project_root endif endif - if (l:change_directory is# 'project' && empty(l:cd_string)) + if (l:change_directory is# 'project' && empty(l:cwd)) \|| l:change_directory is# 1 \|| l:change_directory is# 'file' - let l:cd_string = ale#path#BufferCdString(a:buffer) + let l:cwd = '%s:h' endif - return l:cd_string + return l:cwd endfunction function! ale_linters#python#flake8#GetCommand(buffer, version) abort - let l:cd_string = ale_linters#python#flake8#GetCdString(a:buffer) - let l:executable = ale_linters#python#flake8#GetExecutable(a:buffer) let l:exec_args = l:executable =~? 'pipenv$' @@ -76,8 +74,7 @@ function! ale_linters#python#flake8#GetCommand(buffer, version) abort let l:options = ale#Var(a:buffer, 'python_flake8_options') - return l:cd_string - \ . ale#Escape(l:executable) . l:exec_args + return ale#Escape(l:executable) . l:exec_args \ . (!empty(l:options) ? ' ' . l:options : '') \ . ' --format=default' \ . l:display_name_args . ' -' @@ -161,6 +158,7 @@ endfunction call ale#linter#Define('python', { \ 'name': 'flake8', \ 'executable': function('ale_linters#python#flake8#GetExecutable'), +\ 'cwd': function('ale_linters#python#flake8#GetCwd'), \ 'command': function('ale_linters#python#flake8#RunWithVersionCheck'), \ 'callback': 'ale_linters#python#flake8#Handle', \}) diff --git a/ale_linters/python/mypy.vim b/ale_linters/python/mypy.vim index 1e35d929..48697421 100644 --- a/ale_linters/python/mypy.vim +++ b/ale_linters/python/mypy.vim @@ -18,7 +18,7 @@ function! ale_linters#python#mypy#GetExecutable(buffer) abort endfunction " The directory to change to before running mypy -function! s:GetDir(buffer) abort +function! ale_linters#python#mypy#GetCwd(buffer) abort " If we find a directory with "mypy.ini" in it use that, " else try and find the "python project" root, or failing " that, run from the same folder as the current file @@ -36,26 +36,19 @@ function! s:GetDir(buffer) abort endfunction function! ale_linters#python#mypy#GetCommand(buffer) abort - let l:dir = s:GetDir(a:buffer) let l:executable = ale_linters#python#mypy#GetExecutable(a:buffer) - let l:exec_args = l:executable =~? 'pipenv$' \ ? ' run mypy' \ : '' - let l:options = ale#Var(a:buffer, 'python_mypy_options') - - " We have to always switch to an explicit directory for a command so - " we can know with certainty the base path for the 'filename' keys below. - return ale#path#CdString(l:dir) - \ . ale#Escape(l:executable) . l:exec_args - \ . (len(l:options) ? (' ' . l:options) : '') + return '%e' . l:exec_args + \ . ale#Pad(ale#Var(a:buffer, 'python_mypy_options')) \ . ' --show-column-numbers' \ . ' --shadow-file %s %t %s' endfunction function! ale_linters#python#mypy#Handle(buffer, lines) abort - let l:dir = s:GetDir(a:buffer) + let l:dir = ale_linters#python#mypy#GetCwd(a:buffer) " Look for lines like the following: " " file.py:4: error: No library stub file for module 'django.db' @@ -97,6 +90,7 @@ endfunction call ale#linter#Define('python', { \ 'name': 'mypy', \ 'executable': function('ale_linters#python#mypy#GetExecutable'), +\ 'cwd': function('ale_linters#python#mypy#GetCwd'), \ 'command': function('ale_linters#python#mypy#GetCommand'), \ 'callback': 'ale_linters#python#mypy#Handle', \ 'output_stream': 'both' diff --git a/ale_linters/python/pydocstyle.vim b/ale_linters/python/pydocstyle.vim index 69ae3807..abf95fa1 100644 --- a/ale_linters/python/pydocstyle.vim +++ b/ale_linters/python/pydocstyle.vim @@ -21,8 +21,7 @@ function! ale_linters#python#pydocstyle#GetCommand(buffer) abort \ ? ' run pydocstyle' \ : '' - return ale#path#BufferCdString(a:buffer) - \ . ale#Escape(l:executable) . l:exec_args + return ale#Escape(l:executable) . l:exec_args \ . ale#Pad(ale#Var(a:buffer, 'python_pydocstyle_options')) \ . ' %s:t' endfunction @@ -66,6 +65,7 @@ endfunction call ale#linter#Define('python', { \ 'name': 'pydocstyle', \ 'executable': function('ale_linters#python#pydocstyle#GetExecutable'), +\ 'cwd': '%s:h', \ 'command': function('ale_linters#python#pydocstyle#GetCommand'), \ 'callback': 'ale_linters#python#pydocstyle#Handle', \}) diff --git a/ale_linters/python/pylama.vim b/ale_linters/python/pylama.vim index 38dd2836..bad69667 100644 --- a/ale_linters/python/pylama.vim +++ b/ale_linters/python/pylama.vim @@ -16,19 +16,20 @@ function! ale_linters#python#pylama#GetExecutable(buffer) abort return ale#python#FindExecutable(a:buffer, 'python_pylama', ['pylama']) endfunction -function! ale_linters#python#pylama#GetCommand(buffer) abort - let l:cd_string = '' - +function! ale_linters#python#pylama#GetCwd(buffer) abort if ale#Var(a:buffer, 'python_pylama_change_directory') " Pylama loads its configuration from the current directory only, and " applies file masks using paths relative to the current directory. " Run from project root, if found, otherwise buffer dir. let l:project_root = ale#python#FindProjectRoot(a:buffer) - let l:cd_string = l:project_root isnot# '' - \ ? ale#path#CdString(l:project_root) - \ : ale#path#BufferCdString(a:buffer) + + return !empty(l:project_root) ? l:project_root : '%s:h' endif + return '' +endfunction + +function! ale_linters#python#pylama#GetCommand(buffer) abort let l:executable = ale_linters#python#pylama#GetExecutable(a:buffer) let l:exec_args = l:executable =~? 'pipenv$' \ ? ' run pylama' @@ -37,8 +38,7 @@ function! ale_linters#python#pylama#GetCommand(buffer) abort " Note: Using %t to lint changes would be preferable, but many pylama " checks use surrounding paths (e.g. C0103 module name, E0402 relative " import beyond top, etc.). Neither is ideal. - return l:cd_string - \ . ale#Escape(l:executable) . l:exec_args + return ale#Escape(l:executable) . l:exec_args \ . ale#Pad(ale#Var(a:buffer, 'python_pylama_options')) \ . ' %s' endfunction @@ -86,6 +86,7 @@ endfunction call ale#linter#Define('python', { \ 'name': 'pylama', \ 'executable': function('ale_linters#python#pylama#GetExecutable'), +\ 'cwd': function('ale_linters#python#pylama#GetCwd'), \ 'command': function('ale_linters#python#pylama#GetCommand'), \ 'callback': 'ale_linters#python#pylama#Handle', \ 'lint_file': 1, diff --git a/ale_linters/python/pylint.vim b/ale_linters/python/pylint.vim index 44eea246..f086a865 100644 --- a/ale_linters/python/pylint.vim +++ b/ale_linters/python/pylint.vim @@ -17,27 +17,26 @@ function! ale_linters#python#pylint#GetExecutable(buffer) abort return ale#python#FindExecutable(a:buffer, 'python_pylint', ['pylint']) endfunction -function! ale_linters#python#pylint#GetCommand(buffer, version) abort - let l:cd_string = '' - +function! ale_linters#python#pylint#GetCwd(buffer) abort if ale#Var(a:buffer, 'python_pylint_change_directory') " pylint only checks for pylintrc in the packages above its current " directory before falling back to user and global pylintrc. " Run from project root, if found, otherwise buffer dir. let l:project_root = ale#python#FindProjectRoot(a:buffer) - let l:cd_string = l:project_root isnot# '' - \ ? ale#path#CdString(l:project_root) - \ : ale#path#BufferCdString(a:buffer) + + return !empty(l:project_root) ? l:project_root : '%s:h' endif - let l:executable = ale_linters#python#pylint#GetExecutable(a:buffer) + return '' +endfunction +function! ale_linters#python#pylint#GetCommand(buffer, version) abort + let l:executable = ale_linters#python#pylint#GetExecutable(a:buffer) let l:exec_args = l:executable =~? 'pipenv$' \ ? ' run pylint' \ : '' - return l:cd_string - \ . ale#Escape(l:executable) . l:exec_args + return ale#Escape(l:executable) . l:exec_args \ . ale#Pad(ale#Var(a:buffer, 'python_pylint_options')) \ . ' --output-format text --msg-template="{path}:{line}:{column}: {msg_id} ({symbol}) {msg}" --reports n' \ . (ale#semver#GTE(a:version, [2, 4, 0]) ? ' --from-stdin' : '') @@ -104,6 +103,7 @@ call ale#linter#Define('python', { \ '%e --version', \ {buffer, version -> !ale#semver#GTE(version, [2, 4, 0])}, \ )}, +\ 'cwd': function('ale_linters#python#pylint#GetCwd'), \ 'command': {buffer -> ale#semver#RunWithVersionCheck( \ buffer, \ ale#Var(buffer, 'python_pylint_executable'), diff --git a/ale_linters/python/vulture.vim b/ale_linters/python/vulture.vim index d328d262..84ffd49a 100644 --- a/ale_linters/python/vulture.vim +++ b/ale_linters/python/vulture.vim @@ -6,7 +6,6 @@ call ale#Set('python_vulture_options', '') call ale#Set('python_vulture_use_global', get(g:, 'ale_use_global_executables', 0)) call ale#Set('python_vulture_change_directory', 1) - " The directory to change to before running vulture function! s:GetDir(buffer) abort let l:project_root = ale#python#FindProjectRoot(a:buffer) @@ -16,29 +15,28 @@ function! s:GetDir(buffer) abort \ : expand('#' . a:buffer . ':p:h') endfunction - function! ale_linters#python#vulture#GetExecutable(buffer) abort return ale#python#FindExecutable(a:buffer, 'python_vulture', ['vulture']) endfunction +function! ale_linters#python#vulture#GetCwd(buffer) abort + if !ale#Var(a:buffer, 'python_vulture_change_directory') + return '' + endif -function! ale_linters#python#vulture#GetCommand(buffer) abort - let l:change_dir = ale#Var(a:buffer, 'python_vulture_change_directory') - \ ? ale#path#CdString(s:GetDir(a:buffer)) - \ : '' + return s:GetDir(a:buffer) +endfunction +function! ale_linters#python#vulture#GetCommand(buffer) abort let l:executable = ale_linters#python#vulture#GetExecutable(a:buffer) - let l:exec_args = l:executable =~? 'pipenv$' \ ? ' run vulture' \ : '' - let l:lint_dest = ale#Var(a:buffer, 'python_vulture_change_directory') \ ? ' .' \ : ' %s' - return l:change_dir - \ . ale#Escape(l:executable) . l:exec_args + return ale#Escape(l:executable) . l:exec_args \ . ' ' \ . ale#Var(a:buffer, 'python_vulture_options') \ . l:lint_dest @@ -74,6 +72,7 @@ endfunction call ale#linter#Define('python', { \ 'name': 'vulture', \ 'executable': function('ale_linters#python#vulture#GetExecutable'), +\ 'cwd': function('ale_linters#python#vulture#GetCwd'), \ 'command': function('ale_linters#python#vulture#GetCommand'), \ 'callback': 'ale_linters#python#vulture#Handle', \ 'lint_file': 1, |