summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-05-06 19:11:43 +0100
committerw0rp <devw0rp@gmail.com>2017-05-06 19:11:43 +0100
commit2e1c9b0fa574aa2e617734470d5dbec61abee928 (patch)
tree9b9b303a8d47f4415fd63bdc70378b6ef464943e /autoload
parentbf8aae02e8a1a58649c4617008bd38b71b6b602d (diff)
downloadale-2e1c9b0fa574aa2e617734470d5dbec61abee928.zip
#208 Automatically detect pylint in virtualenv directories
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/python.vim27
1 files changed, 27 insertions, 0 deletions
diff --git a/autoload/ale/python.vim b/autoload/ale/python.vim
index 34b35ddb..2c0c9d81 100644
--- a/autoload/ale/python.vim
+++ b/autoload/ale/python.vim
@@ -1,2 +1,29 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Functions for integrating with Python linters.
+
+" 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
+" containing no __init__.py files is found.
+function! ale#python#FindProjectRoot(buffer) abort
+ for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
+ if !filereadable(l:path . '/__init__.py')
+ return l:path
+ endif
+ endfor
+
+ return ''
+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)
+
+ if !empty(l:matches)
+ return fnamemodify(l:matches[-1], ':h:h')
+ endif
+ endfor
+
+ return ''
+endfunction