summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-05-20 13:34:53 +0100
committerw0rp <devw0rp@gmail.com>2017-05-20 13:34:53 +0100
commit65fbf1cdff316090f404bb65f8c8a54a00551650 (patch)
treeae80afc3a50d5cdc4058f79ea62cf4702d00ab5d
parentd012fd1f09c4ffb89130110fa37d4e10fb1c9b6b (diff)
downloadale-65fbf1cdff316090f404bb65f8c8a54a00551650.zip
#563 Use a configurable list of directories for detecting virtualenv paths instead.
-rw-r--r--autoload/ale/python.vim19
-rw-r--r--doc/ale-python.txt15
2 files changed, 30 insertions, 4 deletions
diff --git a/autoload/ale/python.vim b/autoload/ale/python.vim
index 2c0c9d81..067b08b4 100644
--- a/autoload/ale/python.vim
+++ b/autoload/ale/python.vim
@@ -1,6 +1,15 @@
" Author: w0rp <devw0rp@gmail.com>
" 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.
" The root directory is defined as the first directory found while searching
" 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.
function! ale#python#FindVirtualenv(buffer) abort
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)
- return fnamemodify(l:matches[-1], ':h:h')
- endif
+ if filereadable(l:venv_dir . '/bin/activate')
+ return l:venv_dir
+ endif
+ endfor
endfor
return ''
diff --git a/doc/ale-python.txt b/doc/ale-python.txt
index 29646714..0a8b7088 100644
--- a/doc/ale-python.txt
+++ b/doc/ale-python.txt
@@ -3,6 +3,21 @@ 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*
g:ale_python_flake8_executable *g:ale_python_flake8_executable*