Fix python linting/formatting error when in virtual environment (#4865)

Python fixers and linters were failing when vim is running in a virtual
environment that's located in a path containing text `poetry`. The cause
of this was the regular expression `poetry\|pipenv\|uv$` which matches
`poetry` and `pipenv` if they appear anywhere in the virtualenv path.
This commit is contained in:
Walter Kaunda 2024-11-17 04:00:55 +02:00 committed by GitHub
parent 898638abe5
commit 5cc6b933b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 35 additions and 35 deletions

View File

@ -45,7 +45,7 @@ function! ale_linters#python#bandit#GetCommand(buffer) abort
endif
endif
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run bandit'
\ : ''

View File

@ -74,7 +74,7 @@ endfunction
function! ale_linters#python#flake8#GetCommand(buffer, version) abort
let l:executable = ale_linters#python#flake8#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run flake8'
\ : ''

View File

@ -74,7 +74,7 @@ endfunction
function! ale_linters#python#flakehell#GetCommand(buffer, version) abort
let l:executable = ale_linters#python#flakehell#GetExecutable(a:buffer)
if (l:executable =~? 'pipenv\|poetry\|uv$')
if (l:executable =~? '\(pipenv\|poetry\|uv\)$')
let l:exec_args = ' run flakehell'
elseif (l:executable is? 'python')
let l:exec_args = ' -m flakehell'

View File

@ -28,7 +28,7 @@ endfunction
function! ale_linters#python#jedils#GetCommand(buffer) abort
let l:executable = ale_linters#python#jedils#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run jedi-language-server'
\ : ''
let l:env_string = ''

View File

@ -49,7 +49,7 @@ endfunction
function! ale_linters#python#mypy#GetCommand(buffer) abort
let l:executable = ale_linters#python#mypy#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run mypy'
\ : ''

View File

@ -35,7 +35,7 @@ endfunction
function! ale_linters#python#prospector#GetCommand(buffer) abort
let l:executable = ale_linters#python#prospector#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run prospector'
\ : ''

View File

@ -42,7 +42,7 @@ endfunction
function! ale_linters#python#pycln#GetCommand(buffer, version) abort
let l:executable = ale_linters#python#pycln#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pycln'
\ : ''

View File

@ -30,7 +30,7 @@ endfunction
function! ale_linters#python#pycodestyle#GetCommand(buffer) abort
let l:executable = ale_linters#python#pycodestyle#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pycodestyle'
\ : ''

View File

@ -29,7 +29,7 @@ endfunction
function! ale_linters#python#pydocstyle#GetCommand(buffer) abort
let l:executable = ale_linters#python#pydocstyle#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pydocstyle'
\ : ''

View File

@ -29,7 +29,7 @@ endfunction
function! ale_linters#python#pyflakes#GetCommand(buffer) abort
let l:executable = ale_linters#python#pyflakes#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pyflakes'
\ : ''

View File

@ -30,7 +30,7 @@ endfunction
function! ale_linters#python#pylama#RunWithVersionCheck(buffer) abort
let l:executable = ale_linters#python#pylama#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pylama'
\ : ''
@ -59,7 +59,7 @@ endfunction
function! ale_linters#python#pylama#GetCommand(buffer, version) abort
let l:executable = ale_linters#python#pylama#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pylama'
\ : ''

View File

@ -44,7 +44,7 @@ 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\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pylint'
\ : ''

View File

@ -43,7 +43,7 @@ endfunction
function! ale_linters#python#pylsp#GetCommand(buffer) abort
let l:executable = ale_linters#python#pylsp#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pylsp'
\ : ''
let l:env_string = ''

View File

@ -28,7 +28,7 @@ endfunction
function! ale_linters#python#pyre#GetCommand(buffer) abort
let l:executable = ale_linters#python#pyre#GetExecutable(a:buffer)
let l:exec_args = (l:executable =~? 'pipenv\|poetry\|uv$' ? ' run pyre' : '') . ' persistent'
let l:exec_args = (l:executable =~? '\(pipenv\|poetry\|uv\)$' ? ' run pyre' : '') . ' persistent'
return ale#Escape(l:executable) . l:exec_args
endfunction

View File

@ -70,7 +70,7 @@ endfunction
function! ale_linters#python#pyright#GetCommand(buffer) abort
let l:executable = ale_linters#python#pyright#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pyright-langserver'
\ : ''
let l:env_string = ''

View File

@ -41,7 +41,7 @@ endfunction
function! ale_linters#python#refurb#GetCommand(buffer) abort
let l:executable = ale_linters#python#refurb#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run refurb'
\ : ''

View File

@ -47,7 +47,7 @@ endfunction
function! ale_linters#python#ruff#GetCommand(buffer, version) abort
let l:executable = ale_linters#python#ruff#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run ruff'
\ : ''

View File

@ -28,7 +28,7 @@ endfunction
function! ale_linters#python#unimport#GetCommand(buffer) abort
let l:executable = ale_linters#python#unimport#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run unimport'
\ : ''

View File

@ -47,7 +47,7 @@ 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\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run vulture'
\ : ''
let l:lint_dest = ale#Var(a:buffer, 'python_vulture_change_directory')

View File

@ -30,7 +30,7 @@ endfunction
function! ale#fixers#autoflake#Fix(buffer) abort
let l:executable = ale#fixers#autoflake#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run autoflake'
\ : ''

View File

@ -30,7 +30,7 @@ endfunction
function! ale#fixers#autoimport#Fix(buffer) abort
let l:executable = ale#fixers#autoimport#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run autoimport'
\ : ''

View File

@ -30,7 +30,7 @@ endfunction
function! ale#fixers#autopep8#Fix(buffer) abort
let l:executable = ale#fixers#autopep8#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run autopep8'
\ : ''

View File

@ -32,7 +32,7 @@ function! ale#fixers#black#Fix(buffer) abort
let l:executable = ale#fixers#black#GetExecutable(a:buffer)
let l:cmd = [ale#Escape(l:executable)]
if l:executable =~? 'pipenv\|poetry\|uv$'
if l:executable =~? '\(pipenv\|poetry\|uv\)$'
call extend(l:cmd, ['run', 'black'])
endif

View File

@ -31,7 +31,7 @@ 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\|uv$'
if l:executable =~? '\(pipenv\|poetry\|uv\)$'
call extend(l:cmd, ['run', 'isort'])
endif
@ -42,7 +42,7 @@ function! ale#fixers#isort#FixForVersion(buffer, version) abort
let l:executable = ale#fixers#isort#GetExecutable(a:buffer)
let l:cmd = [ale#Escape(l:executable)]
if l:executable =~? 'pipenv\|poetry\|uv$'
if l:executable =~? '\(pipenv\|poetry\|uv\)$'
call extend(l:cmd, ['run', 'isort'])
endif

View File

@ -42,7 +42,7 @@ endfunction
function! ale#fixers#pycln#GetCommand(buffer) abort
let l:executable = ale#fixers#pycln#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run pycln'
\ : ''
@ -53,7 +53,7 @@ function! ale#fixers#pycln#FixForVersion(buffer, version) abort
let l:executable = ale#fixers#pycln#GetExecutable(a:buffer)
let l:cmd = [ale#Escape(l:executable)]
if l:executable =~? 'pipenv\|poetry\|uv$'
if l:executable =~? '\(pipenv\|poetry\|uv\)$'
call extend(l:cmd, ['run', 'pycln'])
endif

View File

@ -33,7 +33,7 @@ function! ale#fixers#pyflyby#Fix(buffer) abort
let l:executable = ale#fixers#pyflyby#GetExecutable(a:buffer)
let l:cmd = [ale#Escape(l:executable)]
if l:executable =~? 'pipenv\|poetry\|uv$'
if l:executable =~? '\(pipenv\|poetry\|uv\)$'
call extend(l:cmd, ['run', 'tidy-imports'])
endif

View File

@ -30,7 +30,7 @@ endfunction
function! ale#fixers#reorder_python_imports#Fix(buffer) abort
let l:executable = ale#fixers#reorder_python_imports#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run reorder-python-imports'
\ : ''

View File

@ -41,7 +41,7 @@ endfunction
function! ale#fixers#ruff#GetCommand(buffer) abort
let l:executable = ale#fixers#ruff#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run ruff'
\ : ''
@ -52,7 +52,7 @@ function! ale#fixers#ruff#FixForVersion(buffer, version) abort
let l:executable = ale#fixers#ruff#GetExecutable(a:buffer)
let l:cmd = [ale#Escape(l:executable)]
if l:executable =~? 'pipenv\|poetry\|uv$'
if l:executable =~? '\(pipenv\|poetry\|uv\)$'
call extend(l:cmd, ['run', 'ruff'])
endif

View File

@ -41,7 +41,7 @@ endfunction
function! ale#fixers#ruff_format#GetCommand(buffer) abort
let l:executable = ale#fixers#ruff_format#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run ruff'
\ : ''
@ -52,7 +52,7 @@ function! ale#fixers#ruff_format#Fix(buffer) abort
let l:executable = ale#fixers#ruff_format#GetExecutable(a:buffer)
let l:cmd = [ale#Escape(l:executable)]
if l:executable =~? 'pipenv\|poetry\|uv$'
if l:executable =~? '\(pipenv\|poetry\|uv\)$'
call extend(l:cmd, ['run', 'ruff'])
endif

View File

@ -29,7 +29,7 @@ endfunction
function! ale#fixers#yapf#Fix(buffer) abort
let l:executable = ale#fixers#yapf#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv\|poetry\|uv$'
let l:exec_args = l:executable =~? '\(pipenv\|poetry\|uv\)$'
\ ? ' run yapf'
\ : ''