Fix powerline-lint tests

Some notes on the commit:

1. As external_ip and email_imap_alert segments seem to be removed corresponding
   segment_data keys also were removed.
2. Various files that import vim module now have the usual workaround that sets
   vim local to dummy object on error.
3. Syntastic check was failing because it did not specify which highlighting
   groups it uses in documentation. I made it specify them and also moved format
   strings to keywords. Same for some other plugin-local themes.
4. powerline-lint script got --debug argument. Pretty useless currently though:
   it only makes it output traceback for ImportError when failing to import
   module to stderr.
5. Moved themes/vim/plugin/*.json to themes/vim/plugin_*.json.
6. Fixed powerline-lint that ignored problems from values.
This commit is contained in:
ZyX 2013-11-03 00:54:32 +04:00
parent db80fc95ed
commit b5f051f71c
13 changed files with 119 additions and 55 deletions

View File

@ -39,10 +39,10 @@
"help": "help",
"quickfix": "quickfix",
"powerline.matchers.plugin.nerdtree.nerdtree": "plugin/nerdtree",
"powerline.matchers.plugin.ctrlp.ctrlp": "plugin/ctrlp",
"powerline.matchers.plugin.gundo.gundo": "plugin/gundo",
"powerline.matchers.plugin.gundo.gundo_preview": "plugin/gundo-preview"
"powerline.matchers.plugin.nerdtree.nerdtree": "plugin_nerdtree",
"powerline.matchers.plugin.ctrlp.ctrlp": "plugin_ctrlp",
"powerline.matchers.plugin.gundo.gundo": "plugin_gundo",
"powerline.matchers.plugin.gundo.gundo_preview": "plugin_gundo-preview"
}
},
"wm": {

View File

@ -4,18 +4,8 @@
"uptime": {
"before": "⇑ "
},
"external_ip": {
"before": "ⓦ "
},
"date": {
"before": "⌚ "
},
"email_imap_alert": {
"before": "✉ ",
"args": {
"username": "",
"password": ""
}
}
},
"segments": {

View File

@ -1,5 +1,4 @@
{
"default_module": "powerline.segments.plugin.gundo",
"segments": {
"left": [
{

View File

@ -1,5 +1,4 @@
{
"default_module": "powerline.segments.plugin.gundo",
"segments": {
"left": [
{

View File

@ -43,9 +43,22 @@ def context_key(context):
return key_sep.join((c[0] for c in context))
class DelayedEchoErr(object):
def __init__(self, echoerr):
class EchoErr(object):
__slots__ = ('echoerr', 'logger',)
def __init__(self, echoerr, logger):
self.echoerr = echoerr
self.logger = logger
def __call__(self, *args, **kwargs):
self.echoerr(*args, **kwargs)
class DelayedEchoErr(EchoErr):
__slots__ = ('echoerr', 'logger', 'errs')
def __init__(self, echoerr):
super(DelayedEchoErr, self).__init__(echoerr, echoerr.logger)
self.errs = []
def __call__(self, *args, **kwargs):
@ -331,7 +344,9 @@ class Spec(object):
if khadproblem:
hadproblem = True
if proceed:
valspec.match(value[key], value.mark, data, context + ((key, value[key]),), echoerr)
proceed, vhadproblem = valspec.match(value[key], value.mark, data, context + ((key, value[key]),), echoerr)
if vhadproblem:
hadproblem = True
break
else:
hadproblem = True
@ -603,7 +618,9 @@ def check_segment_module(module, data, context, echoerr):
with WithPath(data['import_paths']):
try:
__import__(unicode(module))
except ImportError:
except ImportError as e:
if echoerr.logger.level >= logging.DEBUG:
echoerr.logger.exception(e)
echoerr(context='Error while checking segments (key {key})'.format(key=context_key(context)),
problem='failed to import module {0}'.format(module),
problem_mark=module.mark)
@ -984,13 +1001,19 @@ theme_spec = (Spec(
).context_message('Error while loading theme'))
def check(path=None):
def check(path=None, debug=False):
search_paths = [path] if path else Powerline.get_config_paths()
logger = logging.getLogger('powerline-lint')
logger.setLevel(logging.DEBUG if debug else logging.ERROR)
logger.addHandler(logging.StreamHandler())
ee = EchoErr(echoerr, logger)
dirs = {
'themes': defaultdict(lambda: []),
'colorschemes': defaultdict(lambda: [])
}
'themes': defaultdict(lambda: []),
'colorschemes': defaultdict(lambda: [])
}
for path in reversed(search_paths):
for subdir in ('themes', 'colorschemes'):
d = os.path.join(path, subdir)
@ -1004,14 +1027,16 @@ def check(path=None):
sys.stderr.write('Path {0} is supposed to be a directory, but it is not\n'.format(d))
configs = {
'themes': defaultdict(lambda: {}),
'colorschemes': defaultdict(lambda: {})
}
'themes': defaultdict(lambda: {}),
'colorschemes': defaultdict(lambda: {})
}
for subdir in ('themes', 'colorschemes'):
for ext in dirs[subdir]:
for d in dirs[subdir][ext]:
for config in os.listdir(d):
if config.endswith('.json'):
if os.path.isdir(os.path.join(d, config)):
dirs[subdir][ext].append(os.path.join(d, config))
elif config.endswith('.json'):
configs[subdir][ext][config[:-5]] = os.path.join(d, config)
diff = set(configs['themes']) ^ set(configs['colorschemes'])
@ -1022,7 +1047,7 @@ def check(path=None):
ext,
'configuration' if (ext in dirs['themes'] and ext in dirs['colorschemes']) else 'directory',
'themes' if ext in configs['themes'] else 'colorschemes',
))
))
lhadproblem = [False]
@ -1044,7 +1069,7 @@ def check(path=None):
sys.stderr.write(str(e) + '\n')
hadproblem = True
else:
if main_spec.match(main_config, data={'configs': configs}, context=(('', main_config),))[1]:
if main_spec.match(main_config, data={'configs': configs}, context=(('', main_config),), echoerr=ee)[1]:
hadproblem = True
import_paths = [os.path.expanduser(path) for path in main_config.get('common', {}).get('paths', [])]
@ -1060,7 +1085,7 @@ def check(path=None):
sys.stderr.write(str(e) + '\n')
hadproblem = True
else:
if colors_spec.match(colors_config, context=(('', colors_config),))[1]:
if colors_spec.match(colors_config, context=(('', colors_config),), echoerr=ee)[1]:
hadproblem = True
if lhadproblem[0]:
@ -1084,7 +1109,7 @@ def check(path=None):
spec = vim_colorscheme_spec
else:
spec = colorscheme_spec
if spec.match(config, context=(('', config),), data=data)[1]:
if spec.match(config, context=(('', config),), data=data, echoerr=ee)[1]:
hadproblem = True
theme_configs = defaultdict(lambda: {})
@ -1105,6 +1130,6 @@ def check(path=None):
'main_config': main_config, 'ext_theme_configs': configs, 'colors_config': colors_config}
for theme, config in configs.items():
data['theme'] = theme
if theme_spec.match(config, context=(('', config),), data=data)[1]:
if theme_spec.match(config, context=(('', config),), data=data, echoerr=ee)[1]:
hadproblem = True
return hadproblem

View File

@ -1,19 +1,22 @@
# vim:fileencoding=utf-8:noet
import os
import vim
try:
import vim
vim.command('''function! Powerline_plugin_ctrlp_main(...)
let b:powerline_ctrlp_type = 'main'
let b:powerline_ctrlp_args = a:000
endfunction''')
vim.command('''function! Powerline_plugin_ctrlp_main(...)
let b:powerline_ctrlp_type = 'main'
let b:powerline_ctrlp_args = a:000
endfunction''')
vim.command('''function! Powerline_plugin_ctrlp_prog(...)
let b:powerline_ctrlp_type = 'prog'
let b:powerline_ctrlp_args = a:000
endfunction''')
vim.command('''function! Powerline_plugin_ctrlp_prog(...)
let b:powerline_ctrlp_type = 'prog'
let b:powerline_ctrlp_args = a:000
endfunction''')
vim.command('''let g:ctrlp_status_func = { 'main': 'Powerline_plugin_ctrlp_main', 'prog': 'Powerline_plugin_ctrlp_prog' }''')
vim.command('''let g:ctrlp_status_func = { 'main': 'Powerline_plugin_ctrlp_main', 'prog': 'Powerline_plugin_ctrlp_prog' }''')
except ImportError:
vim = object() # NOQA
def ctrlp(matcher_info):

View File

@ -1,10 +1,18 @@
# vim:fileencoding=utf-8:noet
import vim
try:
import vim
except ImportError:
vim = object() # NOQA
from powerline.bindings.vim import getbufvar
def ctrlp(pl, side):
'''
Highlight groups used: ``ctrlp.regex`` or ``background``, ``ctrlp.prev`` or ``background``, ``ctrlp.item`` or ``file_name``, ``ctrlp.next`` or ``background``, ``ctrlp.marked`` or ``background``, ``ctrlp.focus`` or ``background``, ``ctrlp.byfname`` or ``background``, ``ctrlp.progress`` or ``file_name``, ``ctrlp.progress`` or ``file_name``.
'''
ctrlp_type = getbufvar('%', 'powerline_ctrlp_type')
ctrlp_args = getbufvar('%', 'powerline_ctrlp_args')
@ -12,6 +20,10 @@ def ctrlp(pl, side):
def ctrlp_stl_left_main(pl, focus, byfname, regex, prev, item, next, marked):
'''
Highlight groups used: ``ctrlp.regex`` or ``background``, ``ctrlp.prev`` or ``background``, ``ctrlp.item`` or ``file_name``, ``ctrlp.next`` or ``background``, ``ctrlp.marked`` or ``background``.
'''
marked = marked[2:-1]
segments = []
@ -54,6 +66,10 @@ def ctrlp_stl_left_main(pl, focus, byfname, regex, prev, item, next, marked):
def ctrlp_stl_right_main(pl, focus, byfname, regex, prev, item, next, marked):
'''
Highlight groups used: ``ctrlp.focus`` or ``background``, ``ctrlp.byfname`` or ``background``.
'''
segments = [
{
'contents': focus,
@ -72,6 +88,10 @@ def ctrlp_stl_right_main(pl, focus, byfname, regex, prev, item, next, marked):
def ctrlp_stl_left_prog(pl, progress):
'''
Highlight groups used: ``ctrlp.progress`` or ``file_name``.
'''
return [
{
'contents': 'Loading...',
@ -81,6 +101,10 @@ def ctrlp_stl_left_prog(pl, progress):
def ctrlp_stl_right_prog(pl, progress):
'''
Highlight groups used: ``ctrlp.progress`` or ``file_name``.
'''
return [
{
'contents': progress,

View File

@ -1,6 +1,9 @@
# vim:fileencoding=utf-8:noet
import vim
try:
import vim
except ImportError:
vim = object() # NOQA
from powerline.bindings.vim import getbufvar
from powerline.segments.vim import window_cached
@ -8,6 +11,10 @@ from powerline.segments.vim import window_cached
@window_cached
def nerdtree(pl):
'''Return directory that is shown by the current buffer.
Highlight groups used: ``nerdtree.path`` or ``file_name``.
'''
ntr = getbufvar('%', 'NERDTreeRoot')
if not ntr:
return

View File

@ -1,12 +1,25 @@
# vim:fileencoding=utf-8:noet
import vim
try:
import vim
except ImportError:
vim = object() # NOQA
from powerline.segments.vim import window_cached
@window_cached
def syntastic(pl):
def syntastic(pl, err_format='ERR:  {first_line} ({num}) ', warn_format='WARN:  {first_line} ({num}) '):
'''Show whether syntastic has found any errors or warnings
:param str err_format:
Format string for errors.
:param str warn_format:
Format string for warnings.
Highlight groups used: ``syntastic.warning`` or ``warning``, ``syntastic.error`` or ``error``.
'''
if not int(vim.eval('exists("g:SyntasticLoclist")')):
return
has_errors = int(vim.eval('g:SyntasticLoclist.current().hasErrorsOrWarningsToDisplay()'))
@ -17,12 +30,12 @@ def syntastic(pl):
segments = []
if errors:
segments.append({
'contents': 'ERR:  {line} ({num}) '.format(line=errors[0]['lnum'], num=len(errors)),
'highlight_group': ['syntastic.error', 'error', 'background'],
})
'contents': err_format.format(first_line=errors[0]['lnum'], num=len(errors)),
'highlight_group': ['syntastic.error', 'error'],
})
if warnings:
segments.append({
'contents': 'WARN:  {line} ({num}) '.format(line=warnings[0]['lnum'], num=len(warnings)),
'highlight_group': ['syntastic.warning', 'warning', 'background'],
})
'contents': warn_format.format(first_line=warnings[0]['lnum'], num=len(warnings)),
'highlight_group': ['syntastic.warning', 'warning'],
})
return segments

View File

@ -1,6 +1,9 @@
# vim:fileencoding=utf-8:noet
import vim
try:
import vim
except ImportError:
vim = object() # NOQA
from powerline.segments.vim import window_cached

View File

@ -8,7 +8,8 @@ import sys
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('-p', '--config_path', metavar='PATH')
parser.add_argument('-d', '--debug', action='store_const', const=True)
if __name__ == '__main__':
args = parser.parse_args()
sys.exit(check(args.config_path))
sys.exit(check(args.config_path, args.debug))