Skip to content

Commit

Permalink
Fix python linting/formatting error when in virtual environment (#4865)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kwalter94 authored Nov 17, 2024
1 parent 898638a commit 5cc6b93
Show file tree
Hide file tree
Showing 30 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion ale_linters/python/bandit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/flake8.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/flakehell.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/jedils.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/mypy.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/prospector.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pycln.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pycodestyle.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pydocstyle.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pyflakes.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
4 changes: 2 additions & 2 deletions ale_linters/python/pylama.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pylint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pylsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pyre.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/pyright.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/refurb.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/ruff.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/unimport.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion ale_linters/python/vulture.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion autoload/ale/fixers/autoflake.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion autoload/ale/fixers/autoimport.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion autoload/ale/fixers/autopep8.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
2 changes: 1 addition & 1 deletion autoload/ale/fixers/black.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions autoload/ale/fixers/isort.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions autoload/ale/fixers/pycln.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion autoload/ale/fixers/pyflyby.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion autoload/ale/fixers/reorder_python_imports.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down
4 changes: 2 additions & 2 deletions autoload/ale/fixers/ruff.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions autoload/ale/fixers/ruff_format.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion autoload/ale/fixers/yapf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
\ : ''

Expand Down

0 comments on commit 5cc6b93

Please sign in to comment.