summaryrefslogtreecommitdiff
path: root/autoload/ale/python.vim
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2023-02-08 09:11:31 +0000
committerw0rp <devw0rp@gmail.com>2023-02-08 09:11:31 +0000
commit4c162877e2943ac8f6b29bc79ccf313f8eb88ba6 (patch)
tree7f40105c0a914615ae3bd1bdfb607d1409222b9f /autoload/ale/python.vim
parent6ff1f0b200f9d280b44b9fa59fde232bdb9fe32f (diff)
downloadale-4c162877e2943ac8f6b29bc79ccf313f8eb88ba6.zip
#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`.
Diffstat (limited to 'autoload/ale/python.vim')
-rw-r--r--autoload/ale/python.vim20
1 files changed, 19 insertions, 1 deletions
diff --git a/autoload/ale/python.vim b/autoload/ale/python.vim
index 7a998414..92e48da8 100644
--- a/autoload/ale/python.vim
+++ b/autoload/ale/python.vim
@@ -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