mirror of https://github.com/dense-analysis/ale
Look for ini file to spot python project root (#755)
* Look for ini file to spot project root When looking for the project root folder it would be better to check for some well-known init file instead of __init__.py. Indeed, with python3 it is now possible to have namespace modules where intermediate dirs are not required to include the __init__.py file. * Break if statement conditions over several lines * Add blank lines for the if block * Add test for FindProjectRoot * Typo: missing / for MANIFEST.in * Fix test for non-namespace package * Add more test cases
This commit is contained in:
parent
768f761017
commit
505d114a68
|
@ -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
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
include README.md
|
||||
include *.ini *.cfg *.txt
|
||||
include requirements/*.txt
|
|
@ -0,0 +1,2 @@
|
|||
[pytest]
|
||||
DJANGO_SETTINGS_MODULE=foo.settings
|
|
@ -0,0 +1,2 @@
|
|||
[flake8]
|
||||
max-line-length = 119
|
|
@ -0,0 +1,3 @@
|
|||
[tox]
|
||||
envlist =
|
||||
py352
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue