Use YCM python style

This commit is contained in:
Ben Jackson 2020-02-08 18:09:13 +00:00
commit 8052484cc7
14 changed files with 82 additions and 49 deletions

3
.vintrc.yml Normal file
View file

@ -0,0 +1,3 @@
cmdargs:
color: true
severity: style_problem

View file

@ -72,6 +72,29 @@ For more infomration on the test framework, see
[this article](https://vimways.org/2019/a-test-to-attest-to/), authored by the
Vimspector creator.
### Code Style
The code style of the Python code is "YCM" style, because that's how I like it.
[`flake8`][] is used to check for certain errors and code style.
The code style of the Vimscript is largely the same, and it is linted by
[`vint`][].
To run them:
* (optional) Create and activate a virtual env:
`python3 -m venv venv ; source venv/bin/activate`
* Install the development dependencies: `pip install -r dev_requirements.txt`
* Run `flake8`: `flake8 python3/ *.py`
* Run `vint`: `vint autoload/ plugin/ tests/`
They're also run by CI, so please check for lint failures. The canonical
definition of the command to run is the command run in CI, i.e. in
`azure-pipelines.yml`.
# Code of conduct
Please see [code of conduct](CODE_OF_CONDUCT.md).
[vint]: https://github.com/Vimjas/vint
[flake8]: https://flake8.pycqa.org/en/latest/

View file

@ -27,7 +27,7 @@ stages:
- bash: pip3 install -r dev_requirements.txt
displayName: "Install requirements"
- bash: $HOME/.local/bin/vint autoload/ plugin/
- bash: $HOME/.local/bin/vint autoload/ plugin/ tests/
displayName: "Run vint"
- job: 'linux'

View file

@ -1,2 +1,4 @@
flake8==3.7.7
vim-vint==0.3.21
flake8-comprehensions
flake8-ycm>= 0.1.0

View file

@ -529,7 +529,7 @@ def DownloadFileTo( url,
destination,
file_name = None,
checksum = None,
sslcheck = True):
sslcheck = True ):
if not file_name:
file_name = url.split( '/' )[ -1 ]
@ -759,7 +759,7 @@ for name, gadget in GADGETS.items():
destination,
file_name = gadget[ 'download' ].get( 'target' ),
checksum = v.get( 'checksum' ),
sslcheck = not verify_cert_off)
sslcheck = not verify_cert_off )
root = os.path.join( destination, 'root' )
ExtractZipTo( file_path,
root,

View file

@ -112,7 +112,7 @@ class DebugSession( object ):
else:
configuration_name = utils.SelectFromList(
'Which launch configuration?',
sorted( list( configurations.keys() ) ) )
sorted( configurations.keys() ) )
if not configuration_name or configuration_name not in configurations:
return
@ -259,13 +259,13 @@ class DebugSession( object ):
def IfConnected( fct ):
"""Decorator, call fct if self._connected else echo warning"""
@functools.wraps( fct )
def wrapper(self, *args, **kwargs):
def wrapper( self, *args, **kwargs ):
if not self._connection:
utils.UserMessage(
'Vimspector not connected, start a debug session first',
persist=True, error=True )
return
return fct(self, *args, **kwargs)
return fct( self, *args, **kwargs )
return wrapper
def OnChannelData( self, data ):

View file

@ -210,4 +210,4 @@ class OutputView( object ):
'*' if tab_buffer.flag else '' ) )
def GetCategories( self ):
return [ category for category in self._buffers.keys() ]
return list( self._buffers.keys() )

View file

@ -232,7 +232,7 @@ def Escape( msg ):
return msg.replace( "'", "''" )
def UserMessage( msg, persist=False, error=False):
def UserMessage( msg, persist=False, error=False ):
if persist:
_logger.warning( 'User Msg: ' + msg )
else:
@ -242,11 +242,11 @@ def UserMessage( msg, persist=False, error=False):
vim.command( 'redraw' )
try:
if error:
vim.command("echohl WarningMsg")
vim.command( "echohl WarningMsg" )
for line in msg.split( '\n' ):
vim.command( "{0} '{1}'".format( cmd, Escape( line ) ) )
finally:
vim.command('echohl None') if error else None
vim.command( 'echohl None' ) if error else None
vim.command( 'redraw' )
@ -324,7 +324,7 @@ def SetBufferContents( buf, lines, modified=False ):
if not isinstance( lines, list ):
lines = lines.splitlines()
buf[:] = lines
buf[ : ] = lines
finally:
buf.options[ 'modified' ] = modified
@ -347,7 +347,7 @@ def ExpandReferencesInObject( obj, mapping, user_choices ):
return obj
def ExpandReferencesInString( orig_s, mapping, user_choices):
def ExpandReferencesInString( orig_s, mapping, user_choices ):
s = os.path.expanduser( orig_s )
s = os.path.expandvars( s )

View file

@ -275,7 +275,7 @@ function! Test_Insert_Code_Above_Breakpoint()
" CHeck that we break at the right point
call setpos( '.', [ 0, 1, 1 ] )
call vimspector#LaunchWithSettings( { "configuration": "run" } )
call vimspector#LaunchWithSettings( { 'configuration': 'run' } )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 1 )
call vimspector#Reset()
call vimspector#test#setup#WaitForReset()

View file

@ -28,7 +28,7 @@ function! Test_Python_Simple()
call setpos( '.', [ 0, 1, 1 ] )
" Here we go. Start Debugging
call vimspector#LaunchWithSettings( { "configuration": "run" } )
call vimspector#LaunchWithSettings( { 'configuration': 'run' } )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 6, 1 )
" Step

View file

@ -28,7 +28,7 @@ endif
func RunVimInTerminal(arguments, options)
" If Vim doesn't exit a swap file remains, causing other tests to fail.
" Remove it here.
call delete(".swp")
call delete('.swp')
if exists('$COLORFGBG')
" Clear $COLORFGBG to avoid 'background' being set to "dark", which will
@ -61,7 +61,7 @@ func RunVimInTerminal(arguments, options)
\ 'term_rows': rows,
\ 'term_cols': cols,
\ })
if &termwinsize == ''
if &termwinsize ==# ''
" in the GUI we may end up with a different size, try to set it.
if term_getsize(buf) != [rows, cols]
call term_setsize(buf, rows, cols)
@ -80,7 +80,7 @@ func RunVimInTerminal(arguments, options)
call WaitFor({-> len(term_getline(buf, rows)) >= cols - 1 || len(term_getline(buf, rows - statusoff)) >= cols - 1})
catch /timed out after/
let lines = map(range(1, rows), {key, val -> term_getline(buf, val)})
call assert_report('RunVimInTerminal() failed, screen contents: ' . join(lines, "<NL>"))
call assert_report('RunVimInTerminal() failed, screen contents: ' . join(lines, '<NL>'))
endtry
return buf
@ -88,7 +88,7 @@ endfunc
" Stop a Vim running in terminal buffer "buf".
func StopVimInTerminal(buf)
call assert_equal("running", term_getstatus(a:buf))
call assert_equal('running', term_getstatus(a:buf))
" CTRL-O : works both in Normal mode and Insert mode to start a command line.
" In Command-line it's inserted, the CTRL-U removes it again.

View file

@ -37,8 +37,8 @@ endfunc
func RunCommand(cmd)
let job = 0
if has('job')
let job = job_start(a:cmd, {"stoponexit": "hup"})
call job_setoptions(job, {"stoponexit": "kill"})
let job = job_start(a:cmd, {'stoponexit': 'hup'})
call job_setoptions(job, {'stoponexit': 'kill'})
elseif has('win32')
exe 'silent !start cmd /c start "test_channel" ' . a:cmd
else
@ -53,7 +53,7 @@ func GetPort()
" with 200 it sometimes failed
for i in range(400)
try
let l = readfile("Xportnr")
let l = readfile('Xportnr')
catch
endtry
if len(l) >= 1
@ -61,7 +61,7 @@ func GetPort()
endif
sleep 10m
endfor
call delete("Xportnr")
call delete('Xportnr')
if len(l) == 0
" Can't make the connection, give up.
@ -74,14 +74,14 @@ endfunc
" Always kills the server before returning.
func RunServer(cmd, testfunc, args)
" The Python program writes the port number in Xportnr.
call delete("Xportnr")
call delete('Xportnr')
if len(a:args) == 1
let arg = ' ' . a:args[0]
else
let arg = ''
endif
let pycmd = s:python . " " . a:cmd . arg
let pycmd = s:python . ' ' . a:cmd . arg
try
let g:currentJob = RunCommand(pycmd)
@ -108,10 +108,10 @@ func s:kill_server(cmd)
unlet g:currentJob
endif
elseif has('win32')
let cmd = substitute(a:cmd, ".py", '', '')
let cmd = substitute(a:cmd, '.py', '', '')
call system('taskkill /IM ' . s:python . ' /T /F /FI "WINDOWTITLE eq ' . cmd . '"')
else
call system("pkill -f " . a:cmd)
call system('pkill -f ' . a:cmd)
endif
endfunc
@ -253,7 +253,7 @@ func GetVimCommand(...)
" "vimcmd" file, including environment options.
" Other Makefiles just write the executable in the first line, so fall back
" to that if there is no second line or it is empty.
if len(lines) > 1 && lines[1] != ''
if len(lines) > 1 && lines[1] !=# ''
let cmd = lines[1]
else
let cmd = lines[0]
@ -267,7 +267,7 @@ func GetVimCommand(...)
let cmd = substitute(cmd, 'VIMRUNTIME=.*VIMRUNTIME;', '', '')
" If using valgrind, make sure every run uses a different log file.
if cmd =~ 'valgrind.*--log-file='
if cmd =~# 'valgrind.*--log-file='
let cmd = substitute(cmd, '--log-file=\(^\s*\)', '--log-file=\1.' . g:valgrind_cnt, '')
let g:valgrind_cnt += 1
endif
@ -308,7 +308,7 @@ func RunVimPiped(before, after, arguments, pipecmd)
let args .= ' -S Xafter.vim'
endif
exe "silent !" . a:pipecmd . cmd . args . ' ' . a:arguments
exe 'silent !' . a:pipecmd . cmd . args . ' ' . a:arguments
if len(a:before) > 0
call delete('Xbefore.vim')
@ -320,7 +320,7 @@ func RunVimPiped(before, after, arguments, pipecmd)
endfunc
func CanRunGui()
return has('gui') && ($DISPLAY != "" || has('gui_running'))
return has('gui') && ($DISPLAY !=# '' || has('gui_running'))
endfunc
func WorkingClipboard()
@ -328,7 +328,7 @@ func WorkingClipboard()
return 0
endif
if has('x11')
return $DISPLAY != ""
return $DISPLAY !=# ''
endif
return 1
endfunc

View file

@ -36,16 +36,18 @@
let s:single_test_timeout = 60000
" Restrict the runtimepath to the exact minimum needed for testing
set rtp=$PWD/lib,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after
set runtimepath=$PWD/lib,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after
if has('packages')
let &packpath = &rtp
let &packpath = &runtimepath
endif
call ch_logfile( 'debuglog', 'w' )
" For consistency run all tests with 'nocompatible' set.
" This also enables use of line continuation.
set nocp
" vint: -ProhibitSetNoCompatible
set nocompatible
" vint: +ProhibitSetNoCompatible
" Use utf-8 by default, instead of whatever the system default happens to be.
" Individual tests can overrule this at the top of the file.
@ -93,7 +95,7 @@ func RunTheTest(test)
" directory after executing the test.
let save_cwd = getcwd()
if exists("*SetUp_" . a:test)
if exists('*SetUp_' . a:test)
try
exe 'call SetUp_' . a:test
catch
@ -109,7 +111,7 @@ func RunTheTest(test)
endtry
endif
if exists("*SetUp")
if exists('*SetUp')
try
call SetUp()
catch
@ -136,9 +138,14 @@ func RunTheTest(test)
let test_filesafe = substitute( a:test, '[)(,:]', '_', 'g' )
let s:testid_filesafe = g:testpath . '_' . test_filesafe
au VimLeavePre * call EarlyExit(s:test)
augroup EarlyExit
au!
au VimLeavePre * call EarlyExit(s:test)
augroup END
exe 'call ' . a:test
au! VimLeavePre
au! EarlyExit
catch /^\cskipped/
call add(s:messages, ' Skipped')
call add(s:skipped,
@ -164,7 +171,7 @@ func RunTheTest(test)
" reset to avoid trouble with anything else.
set noinsertmode
if exists("*TearDown")
if exists('*TearDown')
try
call TearDown()
catch
@ -179,7 +186,7 @@ func RunTheTest(test)
endtry
endif
if exists("*TearDown_" . a:test)
if exists('*TearDown_' . a:test)
try
exe 'call TearDown_' . a:test
catch
@ -252,10 +259,9 @@ func FinishTesting()
if filereadable( 'test.log' )
let l = readfile( 'test.log' )
endif
call writefile( l->extend( [ '', 'From ' . g:testpath . ':' ] )
\ ->extend( s:errors ),
\ 'test.log',
\ 's' )
call extend( l, [ '', 'From ' . g:testpath . ':' ] )
call extend( l, s:errors )
call writefile( l, 'test.log', 's' )
endif
if s:done == 0
@ -280,10 +286,9 @@ func FinishTesting()
if filereadable( 'messages' )
let l = readfile( 'messages' )
endif
call writefile( l->extend( [ '', 'From ' . g:testpath . ':' ] )
\ ->extend( s:messages ),
\ 'messages',
\ 's' )
call extend( l, [ '', 'From ' . g:testpath . ':' ] )
call extend( l, s:messages )
call writefile( l, 'messages', 's' )
if s:fail > 0
cquit!

View file

@ -28,7 +28,7 @@ function! Test_Step_With_Different_Tabpage()
call assert_equal( 1, col( '.' ), 'Current column' )
" Switch to the other tab
normal gt
normal! gt
call assert_notequal( vimspector_tabnr, tabpagenr() )