summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2023-03-07 01:59:05 +0000
committerw0rp <devw0rp@gmail.com>2023-03-07 01:59:11 +0000
commitbb691d6dee1979dffd3f40b7ae055707cebe2e33 (patch)
treeb1e8a7cd4a98792c838f3ff1ab8ead7461cdc21b
parent6ae26df22b982e8b19824af96b3e937a0de0bf59 (diff)
downloadale-bb691d6dee1979dffd3f40b7ae055707cebe2e33.zip
#2172 - Expand PATH in the shell for automatic virtualenv
-rw-r--r--autoload/ale/python.vim15
-rw-r--r--test/linter/test_jedils.vader3
-rw-r--r--test/linter/test_pylsp.vader3
-rw-r--r--test/linter/test_pyright.vader3
-rw-r--r--test/test_python_virtualenv.vader11
5 files changed, 26 insertions, 9 deletions
diff --git a/autoload/ale/python.vim b/autoload/ale/python.vim
index 0766551d..615986f9 100644
--- a/autoload/ale/python.vim
+++ b/autoload/ale/python.vim
@@ -100,15 +100,18 @@ endfunction
" 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:pathsep = has('win32') ? ';' : ':'
if !empty(l:venv_dir)
- let l:vars = [
- \ ['PATH', l:venv_dir . s:sep . s:bin_dir . l:pathsep . $PATH],
- \]
+ let l:strs = [ ]
- " 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])'), '')
+ " expand PATH correctly inside of the appropriate shell.
+ if has('win32')
+ call add(l:strs, 'set PATH=' . ale#Escape(l:venv_dir) . ';%PATH% && ')
+ else
+ call add(l:strs, 'PATH=' . ale#Escape(l:venv_dir) . '":$PATH" ')
+ endif
+
+ return join(l:strs, '')
endif
return ''
diff --git a/test/linter/test_jedils.vader b/test/linter/test_jedils.vader
index 3d52b1b5..5ffd22d8 100644
--- a/test/linter/test_jedils.vader
+++ b/test/linter/test_jedils.vader
@@ -31,8 +31,9 @@ Execute(virtualenv vars should be used when ale_python_auto_virtualenv = 1):
let b:sep = has('win32') ? ';' : ':'
let b:executable = ale#path#Simplify(b:venv_bin . '/jedi-language-server')
- AssertLinter b:executable, ale#Env('PATH', b:venv_bin . b:sep . $PATH)
+ AssertLinter b:executable, ale#python#AutoVirtualenvEnvString(bufnr(''))
\ . ale#Escape(b:executable)
+ Assert !empty(ale#python#AutoVirtualenvEnvString(bufnr('')))
Execute(You should be able to override the jedi-language-server virtualenv lookup):
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
diff --git a/test/linter/test_pylsp.vader b/test/linter/test_pylsp.vader
index 1bc56c73..580cec17 100644
--- a/test/linter/test_pylsp.vader
+++ b/test/linter/test_pylsp.vader
@@ -52,8 +52,9 @@ Execute(virtualenv vars should be used when ale_python_auto_virtualenv = 1):
let b:sep = has('win32') ? ';' : ':'
let b:executable = ale#path#Simplify(b:venv_bin . '/pylsp')
- AssertLinter b:executable, ale#Env('PATH', b:venv_bin . b:sep . $PATH)
+ AssertLinter b:executable, ale#python#AutoVirtualenvEnvString(bufnr(''))
\ . ale#Escape(b:executable)
+ Assert !empty(ale#python#AutoVirtualenvEnvString(bufnr('')))
Execute(You should be able to override the pylsp virtualenv lookup):
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
diff --git a/test/linter/test_pyright.vader b/test/linter/test_pyright.vader
index c99877ab..6730d135 100644
--- a/test/linter/test_pyright.vader
+++ b/test/linter/test_pyright.vader
@@ -144,8 +144,9 @@ Execute(virtualenv vars should be used when ale_python_auto_virtualenv = 1):
let b:sep = has('win32') ? ';' : ':'
let b:executable = ale#path#Simplify(b:venv_bin . '/pyright-langserver')
- AssertLinter b:executable, ale#Env('PATH', b:venv_bin . b:sep . $PATH)
+ AssertLinter b:executable, ale#python#AutoVirtualenvEnvString(bufnr(''))
\ . ale#Escape(b:executable) . ' --stdio'
+ Assert !empty(ale#python#AutoVirtualenvEnvString(bufnr('')))
Execute(Setting executable to 'pipenv' should append 'run pyright'):
call ale#test#SetFilename('../test-files')
diff --git a/test/test_python_virtualenv.vader b/test/test_python_virtualenv.vader
index b44c5fa2..cb49d315 100644
--- a/test/test_python_virtualenv.vader
+++ b/test/test_python_virtualenv.vader
@@ -10,3 +10,14 @@ Execute(ale#python#FindVirtualenv falls back to $VIRTUAL_ENV when no directories
\ ale#python#FindVirtualenv(bufnr('%')),
\ '/opt/example/',
\ 'Expected VIRTUAL_ENV environment variable to be used, but it was not'
+
+Execute(ale#python#AutoVirtualenvEnvString should return the correct values):
+ if has('win32')
+ AssertEqual
+ \ 'set PATH=/opt/example/;%PATH% && ',
+ \ ale#python#AutoVirtualenvEnvString(bufnr(''))
+ else
+ AssertEqual
+ \ 'PATH=''/opt/example/''":$PATH" ',
+ \ ale#python#AutoVirtualenvEnvString(bufnr(''))
+ endif