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: Pass user options before any others #3582

Merged
merged 2 commits into from
Feb 11, 2021
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
6 changes: 4 additions & 2 deletions ale_linters/python/mypy.vim
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ function! ale_linters#python#mypy#GetCommand(buffer) abort
\ ? ' run mypy'
\ : ''

let l:options = ale#Var(a:buffer, 'python_mypy_options')

" We have to always switch to an explicit directory for a command so
" we can know with certainty the base path for the 'filename' keys below.
return ale#path#CdString(l:dir)
\ . ale#Escape(l:executable) . l:exec_args
\ . ' --show-column-numbers '
\ . ale#Var(a:buffer, 'python_mypy_options')
\ . (len(l:options) ? (' ' . l:options) : '')
\ . ' --show-column-numbers'
\ . ' --shadow-file %s %t %s'
endfunction

Expand Down
33 changes: 17 additions & 16 deletions test/command_callback/test_mypy_command_callback.vader
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,34 @@ After:
Execute(The mypy callbacks should return the correct default values):
AssertLinter 'mypy',
\ ale#path#CdString(g:dir) . ale#Escape('mypy')
\ . ' --show-column-numbers '
\ . '--shadow-file %s %t %s'
\ . ' --show-column-numbers'
\ . ' --shadow-file %s %t %s'

Execute(The mypy executable should be configurable, and escaped properly):
let g:ale_python_mypy_executable = 'executable with spaces'

AssertLinter 'executable with spaces',
\ ale#path#CdString(g:dir) . ale#Escape('executable with spaces')
\ . ' --show-column-numbers '
\ . '--shadow-file %s %t %s'
\ . ' --show-column-numbers'
\ . ' --shadow-file %s %t %s'

Execute(The mypy command callback should let you set options):
let g:ale_python_mypy_options = '--some-option'

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

Execute(The mypy command should switch directories to the detected project root):
silent execute 'file ' . fnameescape(g:dir . '/python_paths/no_virtualenv/subdir/foo/bar.py')

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

Execute(The mypy callbacks should detect virtualenv directories and switch to the project root):
silent execute 'file ' . fnameescape(g:dir . '/python_paths/with_virtualenv/subdir/foo/bar.py')
Expand All @@ -49,17 +50,17 @@ Execute(The mypy callbacks should detect virtualenv directories and switch to th
AssertLinter b:executable,
\ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/subdir'))
\ . ale#Escape(b:executable)
\ . ' --show-column-numbers '
\ . '--shadow-file %s %t %s'
\ . ' --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'
\ . ' --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')
Expand All @@ -68,21 +69,21 @@ Execute(You should able able to use the global mypy instead):
AssertLinter 'mypy',
\ ale#path#CdString(ale#path#Simplify(g:dir . '/python_paths/with_virtualenv/subdir'))
\ . ale#Escape('mypy')
\ . ' --show-column-numbers '
\ . '--shadow-file %s %t %s'
\ . ' --show-column-numbers'
\ . ' --shadow-file %s %t %s'

Execute(Setting executable to 'pipenv' appends 'run mypy'):
let g:ale_python_mypy_executable = 'path/to/pipenv'

AssertLinter 'path/to/pipenv',
\ ale#path#CdString(expand('#' . bufnr('') . ':p:h'))
\ . ale#Escape('path/to/pipenv') . ' run mypy'
\ . ' --show-column-numbers --shadow-file %s %t %s'
\ . ' --show-column-numbers --shadow-file %s %t %s'

Execute(Pipenv is detected when python_mypy_auto_pipenv is set):
let g:ale_python_mypy_auto_pipenv = 1
call ale#test#SetFilename('../python_fixtures/pipenv/whatever.py')

AssertLinter 'pipenv',
\ ale#path#CdString(expand('#' . bufnr('') . ':p:h'))
\ . ale#Escape('pipenv') . ' run mypy --show-column-numbers --shadow-file %s %t %s'
\ . ale#Escape('pipenv') . ' run mypy --show-column-numbers --shadow-file %s %t %s'