From afb897ec4d530af0460909f5b2d9ddf593c52160 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 19 Sep 2014 21:23:04 +0400 Subject: [PATCH] Run powerline-lint from powerline_troubleshoot function --- powerline/bindings/vim/plugin/powerline.vim | 17 ++++++++++++++- powerline/lint/__init__.py | 23 +++++++++++++++++++-- powerline/lint/markedjson/error.py | 5 +++-- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/powerline/bindings/vim/plugin/powerline.vim b/powerline/bindings/vim/plugin/powerline.vim index 47a24b16..1871cc38 100644 --- a/powerline/bindings/vim/plugin/powerline.vim +++ b/powerline/bindings/vim/plugin/powerline.vim @@ -71,8 +71,10 @@ try call s:rcmd(" sys.path.append(powerline_appended_path)") call s:rcmd(" ".s:import_cmd."") call s:rcmd(" import vim") - call s:rcmd(" VimPowerline().setup(pyeval=vim.eval('s:pyeval'), pycmd=vim.eval('s:pycmd'), can_replace_pyeval=int(vim.eval('s:can_replace_pyeval')))") + call s:rcmd(" powerline_instance = VimPowerline()") + call s:rcmd(" powerline_instance.setup(pyeval=vim.eval('s:pyeval'), pycmd=vim.eval('s:pycmd'), can_replace_pyeval=int(vim.eval('s:can_replace_pyeval')))") call s:rcmd(" del VimPowerline") + call s:rcmd(" del powerline_instance") call s:rcmd("except Exception:") call s:rcmd(" import traceback, sys") call s:rcmd(" traceback.print_exc(file=sys.stdout)") @@ -135,6 +137,19 @@ finally call s:rcmd(" print('one in ' + real_powerline_dir + ', other in ' + real_this_dir + '.')") call s:rcmd(" print('You should remove one of this. Check out troubleshooting section,')") call s:rcmd(" print('it contains some information about the alternatives.')") + call s:rcmd(" try:") + call s:rcmd(" from powerline.lint import check") + call s:rcmd(" except ImportError:") + call s:rcmd(" print('Failed to import powerline.lint.check, cannot run powerline-lint')") + call s:rcmd(" else:") + call s:rcmd(" try:") + call s:rcmd(" paths = powerline_instance.get_config_paths()") + call s:rcmd(" except NameError:") + call s:rcmd(" pass") + call s:rcmd(" else:") + call s:rcmd(" from powerline.lint.markedjson.error import echoerr") + call s:rcmd(" ee = lambda *args, **kwargs: echoerr(*args, stream=sys.stdout, **kwargs)") + call s:rcmd(" check(paths=paths, echoerr=ee, require_ext='vim')") call s:rcmd("try:") call s:rcmd(" powerline_troubleshoot()") call s:rcmd("finally:") diff --git a/powerline/lint/__init__.py b/powerline/lint/__init__.py index 823927cb..ab7a055e 100644 --- a/powerline/lint/__init__.py +++ b/powerline/lint/__init__.py @@ -383,6 +383,10 @@ class Spec(object): self.isoptional = True return self + def required(self): + self.isoptional = False + return self + def match_checks(self, *args): hadproblem = False for check in self.checks: @@ -451,6 +455,12 @@ class Spec(object): problem_mark=key.mark) return True, hadproblem + def __getitem__(self, key): + return self.specs[self.keys[key]] + + def __setitem__(self, key, value): + return self.update(**{key : value}) + class WithPath(object): def __init__(self, import_paths): @@ -1465,7 +1475,7 @@ def generate_json_config_loader(lhadproblem): return load_json_config -def check(paths=None, debug=False, echoerr=echoerr): +def check(paths=None, debug=False, echoerr=echoerr, require_ext=None): search_paths = paths or get_config_paths() find_config_files = generate_config_finder(lambda: search_paths) @@ -1475,6 +1485,15 @@ def check(paths=None, debug=False, echoerr=echoerr): ee = EchoErr(echoerr, logger) + if require_ext: + used_main_spec = main_spec.copy() + try: + used_main_spec['ext'][require_ext].required() + except KeyError: + used_main_spec['ext'][require_ext] = ext_spec() + else: + used_main_spec = main_spec + lhadproblem = [False] load_json_config = generate_json_config_loader(lhadproblem) @@ -1553,7 +1572,7 @@ def check(paths=None, debug=False, echoerr=echoerr): ee(problem=str(e)) hadproblem = True else: - if main_spec.match( + if used_main_spec.match( main_config, data={'configs': configs, 'lists': lists}, context=init_context(main_config), diff --git a/powerline/lint/markedjson/error.py b/powerline/lint/markedjson/error.py index 643c86b3..6494d10f 100644 --- a/powerline/lint/markedjson/error.py +++ b/powerline/lint/markedjson/error.py @@ -68,8 +68,9 @@ class Mark: def echoerr(*args, **kwargs): - sys.stderr.write('\n') - sys.stderr.write(format_error(*args, **kwargs) + '\n') + stream = kwargs.pop('stream', sys.stderr) + stream.write('\n') + stream.write(format_error(*args, **kwargs) + '\n') def format_error(context=None, context_mark=None, problem=None, problem_mark=None, note=None):