#2172 Auto PATH with ale_python_auto_virtualenv

Automatically set `PATH` for some Python linters that seem to need it
when g:ale_python_auto_virtualenv or b:ale_python_auto_virtualenv is
`1`.
This commit is contained in:
w0rp
2023-02-08 09:11:31 +00:00
parent 6ff1f0b200
commit 4c162877e2
10 changed files with 174 additions and 54 deletions

View File

@@ -1,4 +1,4 @@
" Author: w0rp <devw0rp@gmail.com>
" Author: w0rp <dev@w0rp.com>
" Description: Functions for integrating with Python linters.
call ale#Set('python_auto_pipenv', '0')
@@ -96,6 +96,24 @@ function! ale#python#FindVirtualenv(buffer) abort
return $VIRTUAL_ENV
endfunction
" Automatically determine virtualenv environment variables and build
" a string of them to prefix linter commands with.
function! ale#python#AutoVirtualenvEnvString(buffer) abort
let l:venv_dir = ale#python#FindVirtualenv(a:buffer)
let l:sep = has('win32') ? ';' : ':'
if !empty(l:venv_dir)
let l:vars = [
\ ['PATH', ale#path#Simplify(l:venv_dir . '/bin') . l:sep . $PATH],
\]
" We don't need a space between var as ale#Env adds one.
return join(map(l:vars, 'ale#Env(v:val[0], v:val[1])'), '')
endif
return ''
endfunction
" Given a buffer number and a command name, find the path to the executable.
" First search on a virtualenv for Python, if nothing is found, try the global
" command. Returns an empty string if cannot find the executable