Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy: try to find folder containing mypy.ini to use as cwd. #2385

Merged
merged 4 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ale_linters/python/mypy.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ endfunction

" The directory to change to before running mypy
function! s:GetDir(buffer) abort
" If we find a directory with "mypy.ini" in it use that,
" else try and find the "python project" root, or failing
" that, run from the same folder as the current file
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
if filereadable(l:path . '/mypy.ini')
return l:path
endif
endfor

let l:project_root = ale#python#FindProjectRoot(a:buffer)

return !empty(l:project_root)
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions test/command_callback/test_mypy_command_callback.vader
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ Execute(The mypy callbacks should detect virtualenv directories and switch to th
\ . ' --show-column-numbers '
\ . '--shadow-file %s %t %s'

Execute(The mypy callbacks should cd to directory containing mypy.ini if found):
silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_mypy_ini_and_pytest_ini/tests/testsubfolder/my_tests.py')

AssertLinter 'mypy',
\ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/with_mypy_ini_and_pytest_ini'))
\ . ale#Escape('mypy')
\ . ' --show-column-numbers '
\ . '--shadow-file %s %t %s'

Execute(You should able able to use the global mypy instead):
silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py')
let g:ale_python_mypy_use_global = 1
Expand Down