Python support poetry (#3834)

* Add poetry support to python linters and black fixer.

* Update python.vim to detect poetry project.

* Update ale.vim, add an option for poetry `g:ale_python_auto_poetry`.

* Update ale-python.txt, add poetry support.

* Add and update poetry related tests.

Co-authored-by: unc0 <unc0@users.noreply.github.com>
This commit is contained in:
Daniel Roseman
2021-07-25 05:39:05 +01:00
committed by GitHub
parent 530b38de34
commit 7d8fb2ba17
32 changed files with 414 additions and 16 deletions

View File

@@ -48,6 +48,25 @@ Execute(Pipenv is detected when python_bandit_auto_pipenv is set):
\ . b:bandit_flags
\ . ' -'
Execute(Setting executable to 'poetry' appends 'run bandit'):
let g:ale_python_bandit_executable = 'path/to/poetry'
AssertLinter 'path/to/poetry',
\ ale#Escape('path/to/poetry')
\ . ' run bandit'
\ . b:bandit_flags
\ . ' -'
Execute(Poetry is detected when python_bandit_auto_poetry is set):
let g:ale_python_bandit_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertLinter 'poetry',
\ ale#Escape('poetry')
\ . ' run bandit'
\ . b:bandit_flags
\ . ' -'
Execute(The bandit command callback should add .bandit by default):
silent execute 'file ' . fnameescape(g:dir . '/../test-files/python/with_bandit/namespace/foo/bar.py')

View File

@@ -199,3 +199,19 @@ Execute(Pipenv is detected when python_flake8_auto_pipenv is set):
AssertLinterCwd ale#python#FindProjectRootIni(bufnr(''))
AssertLinter 'pipenv',
\ ale#Escape('pipenv') . ' run flake8 --format=default --stdin-display-name %s -'
Execute(Setting executable to 'poetry' should append 'run flake8'):
let g:ale_python_flake8_executable = 'path/to/poetry'
" FIXME: poetry should check the version with flake8.
GivenCommandOutput []
AssertLinter 'path/to/poetry',
\ ale#Escape('path/to/poetry') . ' run flake8 --format=default -'
Execute(poetry is detected when python_flake8_auto_poetry is set):
let g:ale_python_flake8_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertLinterCwd ale#python#FindProjectRootIni(bufnr(''))
AssertLinter 'poetry',
\ ale#Escape('poetry') . ' run flake8 --format=default --stdin-display-name %s -'

View File

@@ -88,3 +88,19 @@ Execute(Pipenv is detected when python_mypy_auto_pipenv is set):
AssertLinterCwd expand('#' . bufnr('') . ':p:h')
AssertLinter 'pipenv',
\ ale#Escape('pipenv') . ' run mypy --show-column-numbers --shadow-file %s %t %s'
Execute(Setting executable to 'poetry' appends 'run mypy'):
let g:ale_python_mypy_executable = 'path/to/poetry'
AssertLinterCwd expand('#' . bufnr('') . ':p:h')
AssertLinter 'path/to/poetry',
\ ale#Escape('path/to/poetry') . ' run mypy'
\ . ' --show-column-numbers --shadow-file %s %t %s'
Execute(Poetry is detected when python_mypy_auto_poetry is set):
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
let g:ale_python_mypy_auto_poetry = 1
AssertLinterCwd expand('#' . bufnr('') . ':p:h')
AssertLinter 'poetry',
\ ale#Escape('poetry') . ' run mypy --show-column-numbers --shadow-file %s %t %s'

View File

@@ -18,3 +18,18 @@ Execute(Pipenv is detected when python_prospector_auto_pipenv is set):
AssertLinter 'pipenv',
\ ale#Escape('pipenv') . ' run prospector'
\ . ' --messages-only --absolute-paths --zero-exit --output-format json %s'
Execute(Setting executable to 'poetry' appends 'run prospector'):
let g:ale_python_prospector_executable = 'path/to/poetry'
AssertLinter 'path/to/poetry',
\ ale#Escape('path/to/poetry') . ' run prospector'
\ . ' --messages-only --absolute-paths --zero-exit --output-format json %s'
Execute(Poetry is detected when python_prospector_auto_poetry is set):
let g:ale_python_prospector_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertLinter 'poetry',
\ ale#Escape('poetry') . ' run prospector'
\ . ' --messages-only --absolute-paths --zero-exit --output-format json %s'

View File

@@ -31,3 +31,16 @@ Execute(Pipenv is detected when python_pycodestyle_auto_pipenv is set):
AssertLinter 'pipenv',
\ ale#Escape('pipenv') . ' run pycodestyle -'
Execute(Setting executable to 'poetry' appends 'run pycodestyle'):
let g:ale_python_pycodestyle_executable = 'path/to/poetry'
AssertLinter 'path/to/poetry',
\ ale#Escape('path/to/poetry') . ' run pycodestyle -'
Execute(Poetry is detected when python_pycodestyle_auto_poetry is set):
let g:ale_python_pycodestyle_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertLinter 'poetry',
\ ale#Escape('poetry') . ' run pycodestyle -'

View File

@@ -31,3 +31,15 @@ Execute(Pipenv is detected when python_pydocstyle_auto_pipenv is set):
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
AssertLinter 'pipenv', ale#Escape('pipenv') . ' run pydocstyle %s:t'
Execute(Setting executable to 'poetry' appends 'run pydocstyle'):
let g:ale_python_pydocstyle_executable = 'path/to/poetry'
AssertLinter 'path/to/poetry',
\ ale#Escape('path/to/poetry') . ' run pydocstyle %s:t'
Execute(Poetry is detected when python_pydocstyle_auto_poetry is set):
let g:ale_python_pydocstyle_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertLinter 'poetry', ale#Escape('poetry') . ' run pydocstyle %s:t'

View File

@@ -44,3 +44,16 @@ Execute(Pipenv is detected when python_pyflakes_auto_pipenv is set):
AssertLinter 'pipenv',
\ ale#Escape('pipenv') . ' run pyflakes %t'
Execute(Setting executable to 'poetry' appends 'run pyflakes'):
let g:ale_python_pyflakes_executable = 'path/to/poetry'
AssertLinter 'path/to/poetry',
\ ale#Escape('path/to/poetry') . ' run pyflakes %t',
Execute(Poetry is detected when python_pyflakes_auto_poetry is set):
let g:ale_python_pyflakes_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertLinter 'poetry',
\ ale#Escape('poetry') . ' run pyflakes %t'

View File

@@ -74,3 +74,15 @@ Execute(Pipenv is detected when python_pylama_auto_pipenv is set):
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
AssertLinter 'pipenv', ale#Escape('pipenv') . ' run pylama' . b:command_tail
Execute(Setting executable to 'poetry' appends 'run pylama'):
let g:ale_python_pylama_executable = 'path/to/poetry'
AssertLinter 'path/to/poetry',
\ ale#Escape('path/to/poetry') . ' run pylama' . b:command_tail
Execute(poetry is detected when python_pylama_auto_poetry is set):
let g:ale_python_pylama_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertLinter 'poetry', ale#Escape('poetry') . ' run pylama' . b:command_tail

View File

@@ -79,3 +79,18 @@ Execute(Pipenv is detected when python_pylint_auto_pipenv is set):
AssertLinterCwd expand('%:p:h')
AssertLinter 'pipenv', ale#Escape('pipenv') . ' run pylint'
\ . ' --output-format text --msg-template="{path}:{line}:{column}: {msg_id} ({symbol}) {msg}" --reports n %s'
Execute(Setting executable to 'poetry' appends 'run pylint'):
let g:ale_python_pylint_executable = 'path/to/poetry'
let g:ale_python_pylint_use_global = 1
AssertLinter 'path/to/poetry', ale#Escape('path/to/poetry') . ' run pylint'
\ . ' --output-format text --msg-template="{path}:{line}:{column}: {msg_id} ({symbol}) {msg}" --reports n %s'
Execute(poetry is detected when python_pylint_auto_poetry is set):
let g:ale_python_pylint_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertLinterCwd expand('%:p:h')
AssertLinter 'poetry', ale#Escape('poetry') . ' run pylint'
\ . ' --output-format text --msg-template="{path}:{line}:{column}: {msg_id} ({symbol}) {msg}" --reports n %s'

View File

@@ -51,6 +51,18 @@ Execute(Pipenv is detected when python_pylsp_auto_pipenv is set):
AssertLinter 'pipenv',
\ ale#Escape('pipenv') . ' run pylsp'
Execute(Setting executable to 'poetry' appends 'run pylsp'):
let g:ale_python_pylsp_executable = 'path/to/poetry'
AssertLinter 'path/to/poetry', ale#Escape('path/to/poetry') . ' run pylsp'
Execute(poetry is detected when python_pylsp_auto_poetry is set):
let g:ale_python_pylsp_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertLinter 'poetry',
\ ale#Escape('poetry') . ' run pylsp'
Execute(Should accept configuration settings):
AssertLSPConfig {}
let b:ale_python_pylsp_config = {'pylsp': {'plugins': {'preload': {'enabled': v:false}}}}

View File

@@ -44,3 +44,16 @@ Execute(Pipenv is detected when python_pyre_auto_pipenv is set):
AssertLinter 'pipenv',
\ ale#Escape('pipenv') . ' run pyre persistent'
Execute(Setting executable to 'poetry' appends 'run pyre'):
let g:ale_python_pyre_executable = 'path/to/poetry'
AssertLinter 'path/to/poetry',
\ ale#Escape('path/to/poetry') . ' run pyre persistent'
Execute(Poetry is detected when python_pyre_auto_poetry is set):
let g:ale_python_pyre_auto_poetry = 1
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
AssertLinter 'poetry',
\ ale#Escape('poetry') . ' run pyre persistent'

View File

@@ -56,3 +56,7 @@ Execute(Setting executable to 'pipenv' appends 'run vulture'):
let g:ale_python_vulture_executable = 'path/to/pipenv'
AssertLinter 'path/to/pipenv', ale#Escape('path/to/pipenv') . ' run vulture' . ' .'
Execute(Setting executable to 'poetry' appends 'run vulture'):
let g:ale_python_vulture_executable = 'path/to/poetry'
AssertLinter 'path/to/poetry', ale#Escape('path/to/poetry') . ' run vulture' . ' .'