summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/python.vim20
-rw-r--r--plugin/ale.vim2
-rw-r--r--test/command_callback/python_paths/namespace_package_manifest/MANIFEST.in3
-rw-r--r--test/command_callback/python_paths/namespace_package_manifest/namespace/foo/__init__.py0
-rw-r--r--test/command_callback/python_paths/namespace_package_manifest/namespace/foo/bar.py0
-rw-r--r--test/command_callback/python_paths/namespace_package_pytest/namespace/foo/__init__.py0
-rw-r--r--test/command_callback/python_paths/namespace_package_pytest/namespace/foo/bar.py0
-rw-r--r--test/command_callback/python_paths/namespace_package_pytest/pytest.ini2
-rw-r--r--test/command_callback/python_paths/namespace_package_setup/namespace/foo/__init__.py0
-rw-r--r--test/command_callback/python_paths/namespace_package_setup/namespace/foo/bar.py0
-rw-r--r--test/command_callback/python_paths/namespace_package_setup/setup.cfg2
-rw-r--r--test/command_callback/python_paths/namespace_package_tox/namespace/foo/__init__.py0
-rw-r--r--test/command_callback/python_paths/namespace_package_tox/namespace/foo/bar.py0
-rw-r--r--test/command_callback/python_paths/namespace_package_tox/tox.ini3
-rw-r--r--test/command_callback/test_flake8_command_callback.vader35
-rw-r--r--test/test_ale_init_au_groups.vader6
16 files changed, 69 insertions, 4 deletions
diff --git a/autoload/ale/python.vim b/autoload/ale/python.vim
index 346163a5..c4fb28f5 100644
--- a/autoload/ale/python.vim
+++ b/autoload/ale/python.vim
@@ -11,11 +11,31 @@ let g:ale_virtualenv_dir_names = get(g:, 'ale_virtualenv_dir_names', [
\ 'virtualenv',
\])
+
+function! ale#python#FindProjectRootIni(buffer) abort
+ for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
+ if filereadable(l:path . '/MANIFEST.in')
+ \|| filereadable(l:path . '/setup.cfg')
+ \|| filereadable(l:path . '/pytest.ini')
+ \|| filereadable(l:path . '/tox.ini')
+ return l:path
+ endif
+ endfor
+
+ return ''
+endfunction
+
" 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
+ let l:ini_root = ale#python#FindProjectRootIni(a:buffer)
+
+ if !empty(l:ini_root)
+ return l:ini_root
+ endif
+
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
if !filereadable(l:path . '/__init__.py')
return l:path
diff --git a/plugin/ale.vim b/plugin/ale.vim
index 50735753..00c24ce6 100644
--- a/plugin/ale.vim
+++ b/plugin/ale.vim
@@ -239,7 +239,7 @@ function! ALEInitAuGroups() abort
augroup ALERunOnSaveGroup
autocmd!
if (g:ale_enabled && g:ale_lint_on_save) || g:ale_fix_on_save
- autocmd BufWrite * call ale#events#SaveEvent()
+ autocmd BufWritePost * call ale#events#SaveEvent()
endif
augroup END
diff --git a/test/command_callback/python_paths/namespace_package_manifest/MANIFEST.in b/test/command_callback/python_paths/namespace_package_manifest/MANIFEST.in
new file mode 100644
index 00000000..4617b0eb
--- /dev/null
+++ b/test/command_callback/python_paths/namespace_package_manifest/MANIFEST.in
@@ -0,0 +1,3 @@
+include README.md
+include *.ini *.cfg *.txt
+include requirements/*.txt
diff --git a/test/command_callback/python_paths/namespace_package_manifest/namespace/foo/__init__.py b/test/command_callback/python_paths/namespace_package_manifest/namespace/foo/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/python_paths/namespace_package_manifest/namespace/foo/__init__.py
diff --git a/test/command_callback/python_paths/namespace_package_manifest/namespace/foo/bar.py b/test/command_callback/python_paths/namespace_package_manifest/namespace/foo/bar.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/python_paths/namespace_package_manifest/namespace/foo/bar.py
diff --git a/test/command_callback/python_paths/namespace_package_pytest/namespace/foo/__init__.py b/test/command_callback/python_paths/namespace_package_pytest/namespace/foo/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/python_paths/namespace_package_pytest/namespace/foo/__init__.py
diff --git a/test/command_callback/python_paths/namespace_package_pytest/namespace/foo/bar.py b/test/command_callback/python_paths/namespace_package_pytest/namespace/foo/bar.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/python_paths/namespace_package_pytest/namespace/foo/bar.py
diff --git a/test/command_callback/python_paths/namespace_package_pytest/pytest.ini b/test/command_callback/python_paths/namespace_package_pytest/pytest.ini
new file mode 100644
index 00000000..1433c6c6
--- /dev/null
+++ b/test/command_callback/python_paths/namespace_package_pytest/pytest.ini
@@ -0,0 +1,2 @@
+[pytest]
+DJANGO_SETTINGS_MODULE=foo.settings
diff --git a/test/command_callback/python_paths/namespace_package_setup/namespace/foo/__init__.py b/test/command_callback/python_paths/namespace_package_setup/namespace/foo/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/python_paths/namespace_package_setup/namespace/foo/__init__.py
diff --git a/test/command_callback/python_paths/namespace_package_setup/namespace/foo/bar.py b/test/command_callback/python_paths/namespace_package_setup/namespace/foo/bar.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/python_paths/namespace_package_setup/namespace/foo/bar.py
diff --git a/test/command_callback/python_paths/namespace_package_setup/setup.cfg b/test/command_callback/python_paths/namespace_package_setup/setup.cfg
new file mode 100644
index 00000000..791f075d
--- /dev/null
+++ b/test/command_callback/python_paths/namespace_package_setup/setup.cfg
@@ -0,0 +1,2 @@
+[flake8]
+max-line-length = 119
diff --git a/test/command_callback/python_paths/namespace_package_tox/namespace/foo/__init__.py b/test/command_callback/python_paths/namespace_package_tox/namespace/foo/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/python_paths/namespace_package_tox/namespace/foo/__init__.py
diff --git a/test/command_callback/python_paths/namespace_package_tox/namespace/foo/bar.py b/test/command_callback/python_paths/namespace_package_tox/namespace/foo/bar.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/python_paths/namespace_package_tox/namespace/foo/bar.py
diff --git a/test/command_callback/python_paths/namespace_package_tox/tox.ini b/test/command_callback/python_paths/namespace_package_tox/tox.ini
new file mode 100644
index 00000000..edd8788c
--- /dev/null
+++ b/test/command_callback/python_paths/namespace_package_tox/tox.ini
@@ -0,0 +1,3 @@
+[tox]
+envlist =
+ py352
diff --git a/test/command_callback/test_flake8_command_callback.vader b/test/command_callback/test_flake8_command_callback.vader
index 42afe65a..70527ad3 100644
--- a/test/command_callback/test_flake8_command_callback.vader
+++ b/test/command_callback/test_flake8_command_callback.vader
@@ -65,6 +65,41 @@ Execute(The flake8 callbacks should detect virtualenv directories):
\ . ' --stdin-display-name %s -',
\ ale_linters#python#flake8#GetCommand(bufnr(''), ['3.0.0'])
+Execute(The FindProjectRoot should detect the project root directory for namespace package via Manifest.in):
+ silent execute 'file ' . fnameescape(g:dir . '/python_paths/namespace_package_manifest/namespace/foo/bar.py')
+
+ AssertEqual
+ \ fnameescape(g:dir . '/python_paths/namespace_package_manifest'),
+ \ ale#python#FindProjectRoot(bufnr(''))
+
+Execute(The FindProjectRoot should detect the project root directory for namespace package via setup.cf):
+ silent execute 'file ' . fnameescape(g:dir . '/python_paths/namespace_package_setup/namespace/foo/bar.py')
+
+ AssertEqual
+ \ fnameescape(g:dir . '/python_paths/namespace_package_setup'),
+ \ ale#python#FindProjectRoot(bufnr(''))
+
+Execute(The FindProjectRoot should detect the project root directory for namespace package via pytest.ini):
+ silent execute 'file ' . fnameescape(g:dir . '/python_paths/namespace_package_pytest/namespace/foo/bar.py')
+
+ AssertEqual
+ \ fnameescape(g:dir . '/python_paths/namespace_package_pytest'),
+ \ ale#python#FindProjectRoot(bufnr(''))
+
+Execute(The FindProjectRoot should detect the project root directory for namespace package via tox.ini):
+ silent execute 'file ' . fnameescape(g:dir . '/python_paths/namespace_package_tox/namespace/foo/bar.py')
+
+ AssertEqual
+ \ fnameescape(g:dir . '/python_paths/namespace_package_tox'),
+ \ ale#python#FindProjectRoot(bufnr(''))
+
+Execute(The FindProjectRoot should detect the project root directory for non-namespace package):
+ silent execute 'file ' . fnameescape(g:dir . '/python_paths/no_virtualenv/subdir/foo/bar.py')
+
+ AssertEqual
+ \ fnameescape(g:dir . '/python_paths/no_virtualenv/subdir'),
+ \ ale#python#FindProjectRoot(bufnr(''))
+
" Some users currently run flake8 this way, so we should support it.
Execute(Using `python -m flake8` should be supported for running flake8):
silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py')
diff --git a/test/test_ale_init_au_groups.vader b/test/test_ale_init_au_groups.vader
index 42dd763e..c20f4f97 100644
--- a/test/test_ale_init_au_groups.vader
+++ b/test/test_ale_init_au_groups.vader
@@ -151,7 +151,7 @@ Execute (g:ale_lint_on_save = 1 should bind no events):
let g:ale_fix_on_save = 0
AssertEqual [
- \ 'BufWritePre * call ale#events#SaveEvent()',
+ \ 'BufWritePost * call ale#events#SaveEvent()',
\], CheckAutocmd('ALERunOnSaveGroup')
Execute (g:ale_lint_on_save = 0 and g:ale_fix_on_save = 1 should bind events):
@@ -159,7 +159,7 @@ Execute (g:ale_lint_on_save = 0 and g:ale_fix_on_save = 1 should bind events):
let g:ale_fix_on_save = 1
AssertEqual [
- \ 'BufWritePre * call ale#events#SaveEvent()',
+ \ 'BufWritePost * call ale#events#SaveEvent()',
\], CheckAutocmd('ALERunOnSaveGroup')
Execute (g:ale_fix_on_save = 1 should bind events even when ALE is disabled):
@@ -168,7 +168,7 @@ Execute (g:ale_fix_on_save = 1 should bind events even when ALE is disabled):
let g:ale_fix_on_save = 1
AssertEqual [
- \ 'BufWritePre * call ale#events#SaveEvent()',
+ \ 'BufWritePost * call ale#events#SaveEvent()',
\], CheckAutocmd('ALERunOnSaveGroup')
Execute (g:ale_echo_cursor = 0 should bind no events):