#563 Use a configurable list of directories for detecting virtualenv paths instead.

This commit is contained in:
w0rp 2017-05-20 13:34:53 +01:00
parent d012fd1f09
commit 65fbf1cdff
2 changed files with 30 additions and 4 deletions

View File

@ -1,6 +1,15 @@
" Author: w0rp <devw0rp@gmail.com> " Author: w0rp <devw0rp@gmail.com>
" Description: Functions for integrating with Python linters. " Description: Functions for integrating with Python linters.
let g:ale_virtualenv_dir_names = get(g:, 'ale_virtualenv_dir_names', [
\ '.env',
\ 'env',
\ 've',
\ 've-py3',
\ 'virtualenv',
\])
" Given a buffer number, find the project root directory for Python. " Given a buffer number, find the project root directory for Python.
" The root directory is defined as the first directory found while searching " The root directory is defined as the first directory found while searching
" upwards through paths, including the current directory, until a path " upwards through paths, including the current directory, until a path
@ -18,11 +27,13 @@ endfunction
" Given a buffer number, find a virtualenv path for Python. " Given a buffer number, find a virtualenv path for Python.
function! ale#python#FindVirtualenv(buffer) abort function! ale#python#FindVirtualenv(buffer) abort
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h')) for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
let l:matches = globpath(l:path, '*/bin/activate', 0, 1) for l:dirname in ale#Var(a:buffer, 'virtualenv_dir_names')
let l:venv_dir = l:path . '/' . l:dirname
if !empty(l:matches) if filereadable(l:venv_dir . '/bin/activate')
return fnamemodify(l:matches[-1], ':h:h') return l:venv_dir
endif endif
endfor
endfor endfor
return '' return ''

View File

@ -2,6 +2,21 @@
ALE Python Integration *ale-python-options* ALE Python Integration *ale-python-options*
-------------------------------------------------------------------------------
Global Options
g:ale_virtualenv_dir_names *g:ale_virtualenv_dir_names*
*b:ale_virtualenv_dir_names*
Type: |List|
Default: `['.env', 'env', 've', 've-py3', 'virtualenv']`
A list of directory names to be used when searching upwards from Python
files to discover virtulenv directories with. For directory named `'foo'`,
ALE will search for `'foo/bin/activate'` in all directories on and above
the directory containing the Python file to find virtualenv paths.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
flake8 *ale-python-flake8* flake8 *ale-python-flake8*