mirror of
https://github.com/powerline/powerline.git
synced 2025-07-30 01:05:42 +02:00
Remove context_key, init_context and context_has_marks functions
This commit is contained in:
parent
346c7ab41e
commit
479305e815
@ -21,7 +21,7 @@ from powerline.lint.checks import (check_matcher_func, check_ext, check_config,
|
|||||||
check_highlight_groups, check_highlight_group, check_full_segment_data,
|
check_highlight_groups, check_highlight_group, check_full_segment_data,
|
||||||
get_all_possible_functions, check_segment_data_key)
|
get_all_possible_functions, check_segment_data_key)
|
||||||
from powerline.lint.spec import Spec
|
from powerline.lint.spec import Spec
|
||||||
from powerline.lint.context import init_context
|
from powerline.lint.context import Context
|
||||||
|
|
||||||
|
|
||||||
def open_file(path):
|
def open_file(path):
|
||||||
@ -389,7 +389,7 @@ def check(paths=None, debug=False, echoerr=echoerr, require_ext=None):
|
|||||||
if used_main_spec.match(
|
if used_main_spec.match(
|
||||||
main_config,
|
main_config,
|
||||||
data={'configs': configs, 'lists': lists},
|
data={'configs': configs, 'lists': lists},
|
||||||
context=init_context(main_config),
|
context=Context(main_config),
|
||||||
echoerr=ee
|
echoerr=ee
|
||||||
)[1]:
|
)[1]:
|
||||||
hadproblem = True
|
hadproblem = True
|
||||||
@ -407,7 +407,7 @@ def check(paths=None, debug=False, echoerr=echoerr, require_ext=None):
|
|||||||
ee(problem=str(e))
|
ee(problem=str(e))
|
||||||
hadproblem = True
|
hadproblem = True
|
||||||
else:
|
else:
|
||||||
if colors_spec.match(colors_config, context=init_context(colors_config), echoerr=ee)[1]:
|
if colors_spec.match(colors_config, context=Context(colors_config), echoerr=ee)[1]:
|
||||||
hadproblem = True
|
hadproblem = True
|
||||||
|
|
||||||
if lhadproblem[0]:
|
if lhadproblem[0]:
|
||||||
@ -432,7 +432,7 @@ def check(paths=None, debug=False, echoerr=echoerr, require_ext=None):
|
|||||||
hadproblem = True
|
hadproblem = True
|
||||||
top_colorscheme_configs[colorscheme] = config
|
top_colorscheme_configs[colorscheme] = config
|
||||||
data['colorscheme'] = colorscheme
|
data['colorscheme'] = colorscheme
|
||||||
if top_colorscheme_spec.match(config, context=init_context(config), data=data, echoerr=ee)[1]:
|
if top_colorscheme_spec.match(config, context=Context(config), data=data, echoerr=ee)[1]:
|
||||||
hadproblem = True
|
hadproblem = True
|
||||||
|
|
||||||
ext_colorscheme_configs = defaultdict(lambda: {})
|
ext_colorscheme_configs = defaultdict(lambda: {})
|
||||||
@ -464,7 +464,7 @@ def check(paths=None, debug=False, echoerr=echoerr, require_ext=None):
|
|||||||
spec = shell_colorscheme_spec
|
spec = shell_colorscheme_spec
|
||||||
else:
|
else:
|
||||||
spec = colorscheme_spec
|
spec = colorscheme_spec
|
||||||
if spec.match(config, context=init_context(config), data=data, echoerr=ee)[1]:
|
if spec.match(config, context=Context(config), data=data, echoerr=ee)[1]:
|
||||||
hadproblem = True
|
hadproblem = True
|
||||||
|
|
||||||
colorscheme_configs = {}
|
colorscheme_configs = {}
|
||||||
@ -533,7 +533,7 @@ def check(paths=None, debug=False, echoerr=echoerr, require_ext=None):
|
|||||||
else:
|
else:
|
||||||
data['theme_type'] = 'regular'
|
data['theme_type'] = 'regular'
|
||||||
spec = theme_spec
|
spec = theme_spec
|
||||||
if spec.match(config, context=init_context(config), data=data, echoerr=ee)[1]:
|
if spec.match(config, context=Context(config), data=data, echoerr=ee)[1]:
|
||||||
hadproblem = True
|
hadproblem = True
|
||||||
|
|
||||||
for top_theme, config in top_theme_configs.items():
|
for top_theme, config in top_theme_configs.items():
|
||||||
@ -548,7 +548,7 @@ def check(paths=None, debug=False, echoerr=echoerr, require_ext=None):
|
|||||||
}
|
}
|
||||||
data['theme_type'] = 'top'
|
data['theme_type'] = 'top'
|
||||||
data['theme'] = top_theme
|
data['theme'] = top_theme
|
||||||
if top_theme_spec.match(config, context=init_context(config), data=data, echoerr=ee)[1]:
|
if top_theme_spec.match(config, context=Context(config), data=data, echoerr=ee)[1]:
|
||||||
hadproblem = True
|
hadproblem = True
|
||||||
|
|
||||||
return hadproblem
|
return hadproblem
|
||||||
|
@ -9,8 +9,8 @@ from powerline.lib.threaded import ThreadedSegment
|
|||||||
from powerline.lib.unicode import unicode
|
from powerline.lib.unicode import unicode
|
||||||
from powerline.lint.markedjson.markedvalue import MarkedUnicode
|
from powerline.lint.markedjson.markedvalue import MarkedUnicode
|
||||||
from powerline.lint.markedjson.error import DelayedEchoErr, Mark
|
from powerline.lint.markedjson.error import DelayedEchoErr, Mark
|
||||||
from powerline.lint.selfcheck import havemarks, context_has_marks
|
from powerline.lint.selfcheck import havemarks
|
||||||
from powerline.lint.context import context_key, list_sep, list_themes, new_context_item
|
from powerline.lint.context import list_sep, list_themes, new_context_item
|
||||||
from powerline.lint.imp import WithPath, import_function, import_segment
|
from powerline.lint.imp import WithPath, import_function, import_segment
|
||||||
from powerline.lint.spec import Spec
|
from powerline.lint.spec import Spec
|
||||||
from powerline.lint.inspect import getconfigargspec
|
from powerline.lint.inspect import getconfigargspec
|
||||||
@ -112,7 +112,6 @@ def check_ext(ext, data, context, echoerr):
|
|||||||
|
|
||||||
|
|
||||||
def check_config(d, theme, data, context, echoerr):
|
def check_config(d, theme, data, context, echoerr):
|
||||||
context_has_marks(context)
|
|
||||||
if len(context) == 4:
|
if len(context) == 4:
|
||||||
ext = context[-2][0]
|
ext = context[-2][0]
|
||||||
else:
|
else:
|
||||||
@ -135,10 +134,9 @@ def check_config(d, theme, data, context, echoerr):
|
|||||||
|
|
||||||
|
|
||||||
def check_top_theme(theme, data, context, echoerr):
|
def check_top_theme(theme, data, context, echoerr):
|
||||||
context_has_marks(context)
|
|
||||||
havemarks(theme)
|
havemarks(theme)
|
||||||
if theme not in data['configs']['top_themes']:
|
if theme not in data['configs']['top_themes']:
|
||||||
echoerr(context='Error while checking extension configuration (key {key})'.format(key=context_key(context)),
|
echoerr(context='Error while checking extension configuration (key {key})'.format(key=context.key),
|
||||||
context_mark=context[-2][0].mark,
|
context_mark=context[-2][0].mark,
|
||||||
problem='failed to find top theme {0}'.format(theme),
|
problem='failed to find top theme {0}'.format(theme),
|
||||||
problem_mark=theme.mark)
|
problem_mark=theme.mark)
|
||||||
@ -152,7 +150,7 @@ def check_color(color, data, context, echoerr):
|
|||||||
and color not in data['colors_config'].get('gradients', {})):
|
and color not in data['colors_config'].get('gradients', {})):
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking highlight group in colorscheme (key {key})'.format(
|
context='Error while checking highlight group in colorscheme (key {key})'.format(
|
||||||
key=context_key(context)),
|
key=context.key),
|
||||||
problem='found unexistent color or gradient {0}'.format(color),
|
problem='found unexistent color or gradient {0}'.format(color),
|
||||||
problem_mark=color.mark
|
problem_mark=color.mark
|
||||||
)
|
)
|
||||||
@ -228,7 +226,7 @@ def check_group(group, data, context, echoerr):
|
|||||||
if not_found:
|
if not_found:
|
||||||
new_echoerr(
|
new_echoerr(
|
||||||
context='Error while checking group definition in colorscheme (key {key})'.format(
|
context='Error while checking group definition in colorscheme (key {key})'.format(
|
||||||
key=context_key(context)),
|
key=context.key),
|
||||||
problem='name {0} is not present in {1} {2} colorschemes: {3}'.format(
|
problem='name {0} is not present in {1} {2} colorschemes: {3}'.format(
|
||||||
group, tofind, ext, ', '.join(not_found)),
|
group, tofind, ext, ', '.join(not_found)),
|
||||||
problem_mark=group.mark
|
problem_mark=group.mark
|
||||||
@ -238,13 +236,12 @@ def check_group(group, data, context, echoerr):
|
|||||||
|
|
||||||
|
|
||||||
def check_key_compatibility(segment, data, context, echoerr):
|
def check_key_compatibility(segment, data, context, echoerr):
|
||||||
context_has_marks(context)
|
|
||||||
havemarks(segment)
|
havemarks(segment)
|
||||||
segment_type = segment.get('type', MarkedUnicode('function', None))
|
segment_type = segment.get('type', MarkedUnicode('function', None))
|
||||||
havemarks(segment_type)
|
havemarks(segment_type)
|
||||||
|
|
||||||
if segment_type not in type_keys:
|
if segment_type not in type_keys:
|
||||||
echoerr(context='Error while checking segments (key {key})'.format(key=context_key(context)),
|
echoerr(context='Error while checking segments (key {key})'.format(key=context.key),
|
||||||
problem='found segment with unknown type {0}'.format(segment_type),
|
problem='found segment with unknown type {0}'.format(segment_type),
|
||||||
problem_mark=segment_type.mark)
|
problem_mark=segment_type.mark)
|
||||||
return False, False, True
|
return False, False, True
|
||||||
@ -255,7 +252,7 @@ def check_key_compatibility(segment, data, context, echoerr):
|
|||||||
if not ((keys - generic_keys) < type_keys[segment_type]):
|
if not ((keys - generic_keys) < type_keys[segment_type]):
|
||||||
unknown_keys = keys - generic_keys - type_keys[segment_type]
|
unknown_keys = keys - generic_keys - type_keys[segment_type]
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking segments (key {key})'.format(key=context_key(context)),
|
context='Error while checking segments (key {key})'.format(key=context.key),
|
||||||
context_mark=context[-1][1].mark,
|
context_mark=context[-1][1].mark,
|
||||||
problem='found keys not used with the current segment type: {0}'.format(
|
problem='found keys not used with the current segment type: {0}'.format(
|
||||||
list_sep.join(unknown_keys)),
|
list_sep.join(unknown_keys)),
|
||||||
@ -266,7 +263,7 @@ def check_key_compatibility(segment, data, context, echoerr):
|
|||||||
if not (keys >= required_keys[segment_type]):
|
if not (keys >= required_keys[segment_type]):
|
||||||
missing_keys = required_keys[segment_type] - keys
|
missing_keys = required_keys[segment_type] - keys
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking segments (key {key})'.format(key=context_key(context)),
|
context='Error while checking segments (key {key})'.format(key=context.key),
|
||||||
context_mark=context[-1][1].mark,
|
context_mark=context[-1][1].mark,
|
||||||
problem='found missing required keys: {0}'.format(
|
problem='found missing required keys: {0}'.format(
|
||||||
list_sep.join(missing_keys))
|
list_sep.join(missing_keys))
|
||||||
@ -275,7 +272,7 @@ def check_key_compatibility(segment, data, context, echoerr):
|
|||||||
|
|
||||||
if not (segment_type == 'function' or (keys & highlight_keys)):
|
if not (segment_type == 'function' or (keys & highlight_keys)):
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking segments (key {key})'.format(key=context_key(context)),
|
context='Error while checking segments (key {key})'.format(key=context.key),
|
||||||
context_mark=context[-1][1].mark,
|
context_mark=context[-1][1].mark,
|
||||||
problem=(
|
problem=(
|
||||||
'found missing keys required to determine highlight group. '
|
'found missing keys required to determine highlight group. '
|
||||||
@ -295,7 +292,7 @@ def check_segment_module(module, data, context, echoerr):
|
|||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
if echoerr.logger.level >= logging.DEBUG:
|
if echoerr.logger.level >= logging.DEBUG:
|
||||||
echoerr.logger.exception(e)
|
echoerr.logger.exception(e)
|
||||||
echoerr(context='Error while checking segments (key {key})'.format(key=context_key(context)),
|
echoerr(context='Error while checking segments (key {key})'.format(key=context.key),
|
||||||
problem='failed to import module {0}'.format(module),
|
problem='failed to import module {0}'.format(module),
|
||||||
problem_mark=module.mark)
|
problem_mark=module.mark)
|
||||||
return True, False, True
|
return True, False, True
|
||||||
@ -382,7 +379,7 @@ def check_segment_function(function_name, data, context, echoerr):
|
|||||||
r = hl_exists(divider_hl_group, data, context, echoerr, allow_gradients=True)
|
r = hl_exists(divider_hl_group, data, context, echoerr, allow_gradients=True)
|
||||||
if r:
|
if r:
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking theme (key {key})'.format(key=context_key(context)),
|
context='Error while checking theme (key {key})'.format(key=context.key),
|
||||||
problem=(
|
problem=(
|
||||||
'found highlight group {0} not defined in the following colorschemes: {1}\n'
|
'found highlight group {0} not defined in the following colorschemes: {1}\n'
|
||||||
'(Group name was obtained from function documentation.)'
|
'(Group name was obtained from function documentation.)'
|
||||||
@ -421,7 +418,7 @@ def check_segment_function(function_name, data, context, echoerr):
|
|||||||
]
|
]
|
||||||
if all(rs):
|
if all(rs):
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking theme (key {key})'.format(key=context_key(context)),
|
context='Error while checking theme (key {key})'.format(key=context.key),
|
||||||
problem=(
|
problem=(
|
||||||
'found highlight groups list ({0}) with all groups not defined in some colorschemes\n'
|
'found highlight groups list ({0}) with all groups not defined in some colorschemes\n'
|
||||||
'(Group names were taken from function documentation.)'
|
'(Group names were taken from function documentation.)'
|
||||||
@ -430,7 +427,7 @@ def check_segment_function(function_name, data, context, echoerr):
|
|||||||
)
|
)
|
||||||
for r, h in zip(rs, required_pack):
|
for r, h in zip(rs, required_pack):
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking theme (key {key})'.format(key=context_key(context)),
|
context='Error while checking theme (key {key})'.format(key=context.key),
|
||||||
problem='found highlight group {0} not defined in the following colorschemes: {1}'.format(
|
problem='found highlight group {0} not defined in the following colorschemes: {1}'.format(
|
||||||
h[0], list_sep.join(r))
|
h[0], list_sep.join(r))
|
||||||
)
|
)
|
||||||
@ -439,7 +436,7 @@ def check_segment_function(function_name, data, context, echoerr):
|
|||||||
r = hl_exists(function_name, data, context, echoerr, allow_gradients=True)
|
r = hl_exists(function_name, data, context, echoerr, allow_gradients=True)
|
||||||
if r:
|
if r:
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking theme (key {key})'.format(key=context_key(context)),
|
context='Error while checking theme (key {key})'.format(key=context.key),
|
||||||
problem=(
|
problem=(
|
||||||
'found highlight group {0} not defined in the following colorschemes: {1}\n'
|
'found highlight group {0} not defined in the following colorschemes: {1}\n'
|
||||||
'(If not specified otherwise in documentation, '
|
'(If not specified otherwise in documentation, '
|
||||||
@ -463,7 +460,7 @@ def check_segment_function(function_name, data, context, echoerr):
|
|||||||
and function_name not in data['ext_theme_configs'].get('__main__', {}).get('segment_data', {})
|
and function_name not in data['ext_theme_configs'].get('__main__', {}).get('segment_data', {})
|
||||||
and not any(((function_name in theme.get('segment_data', {})) for theme in data['top_themes'].values()))
|
and not any(((function_name in theme.get('segment_data', {})) for theme in data['top_themes'].values()))
|
||||||
):
|
):
|
||||||
echoerr(context='Error while checking segments (key {key})'.format(key=context_key(context)),
|
echoerr(context='Error while checking segments (key {key})'.format(key=context.key),
|
||||||
problem='found useless use of name key (such name is not present in theme/segment_data)',
|
problem='found useless use of name key (such name is not present in theme/segment_data)',
|
||||||
problem_mark=function_name.mark)
|
problem_mark=function_name.mark)
|
||||||
|
|
||||||
@ -501,7 +498,7 @@ def hl_exists(hl_group, data, context, echoerr, allow_gradients=False):
|
|||||||
if allow_gradients is False and not hascolor and hasgradient:
|
if allow_gradients is False and not hascolor and hasgradient:
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking highlight group in theme (key {key})'.format(
|
context='Error while checking highlight group in theme (key {key})'.format(
|
||||||
key=context_key(context)),
|
key=context.key),
|
||||||
context_mark=hl_group.mark,
|
context_mark=hl_group.mark,
|
||||||
problem='group {0} is using gradient {1} instead of a color'.format(hl_group, color),
|
problem='group {0} is using gradient {1} instead of a color'.format(hl_group, color),
|
||||||
problem_mark=color.mark
|
problem_mark=color.mark
|
||||||
@ -511,7 +508,7 @@ def hl_exists(hl_group, data, context, echoerr, allow_gradients=False):
|
|||||||
if allow_gradients == 'force' and not hadgradient:
|
if allow_gradients == 'force' and not hadgradient:
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking highlight group in theme (key {key})'.format(
|
context='Error while checking highlight group in theme (key {key})'.format(
|
||||||
key=context_key(context)),
|
key=context.key),
|
||||||
context_mark=hl_group.mark,
|
context_mark=hl_group.mark,
|
||||||
problem='group {0} should have at least one gradient color, but it has no'.format(hl_group),
|
problem='group {0} should have at least one gradient color, but it has no'.format(hl_group),
|
||||||
problem_mark=group_config.mark
|
problem_mark=group_config.mark
|
||||||
@ -525,7 +522,7 @@ def check_highlight_group(hl_group, data, context, echoerr):
|
|||||||
r = hl_exists(hl_group, data, context, echoerr)
|
r = hl_exists(hl_group, data, context, echoerr)
|
||||||
if r:
|
if r:
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking theme (key {key})'.format(key=context_key(context)),
|
context='Error while checking theme (key {key})'.format(key=context.key),
|
||||||
problem='found highlight group {0} not defined in the following colorschemes: {1}'.format(
|
problem='found highlight group {0} not defined in the following colorschemes: {1}'.format(
|
||||||
hl_group, list_sep.join(r)),
|
hl_group, list_sep.join(r)),
|
||||||
problem_mark=hl_group.mark
|
problem_mark=hl_group.mark
|
||||||
@ -539,14 +536,14 @@ def check_highlight_groups(hl_groups, data, context, echoerr):
|
|||||||
rs = [hl_exists(hl_group, data, context, echoerr) for hl_group in hl_groups]
|
rs = [hl_exists(hl_group, data, context, echoerr) for hl_group in hl_groups]
|
||||||
if all(rs):
|
if all(rs):
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking theme (key {key})'.format(key=context_key(context)),
|
context='Error while checking theme (key {key})'.format(key=context.key),
|
||||||
problem='found highlight groups list ({0}) with all groups not defined in some colorschemes'.format(
|
problem='found highlight groups list ({0}) with all groups not defined in some colorschemes'.format(
|
||||||
list_sep.join((unicode(h) for h in hl_groups))),
|
list_sep.join((unicode(h) for h in hl_groups))),
|
||||||
problem_mark=hl_groups.mark
|
problem_mark=hl_groups.mark
|
||||||
)
|
)
|
||||||
for r, hl_group in zip(rs, hl_groups):
|
for r, hl_group in zip(rs, hl_groups):
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking theme (key {key})'.format(key=context_key(context)),
|
context='Error while checking theme (key {key})'.format(key=context.key),
|
||||||
problem='found highlight group {0} not defined in the following colorschemes: {1}'.format(
|
problem='found highlight group {0} not defined in the following colorschemes: {1}'.format(
|
||||||
hl_group, list_sep.join(r)),
|
hl_group, list_sep.join(r)),
|
||||||
problem_mark=hl_group.mark
|
problem_mark=hl_group.mark
|
||||||
@ -611,14 +608,14 @@ def check_args_variant(func, args, data, context, echoerr):
|
|||||||
|
|
||||||
if required_args - present_args:
|
if required_args - present_args:
|
||||||
echoerr(
|
echoerr(
|
||||||
context='Error while checking segment arguments (key {key})'.format(key=context_key(context)),
|
context='Error while checking segment arguments (key {key})'.format(key=context.key),
|
||||||
context_mark=args.mark,
|
context_mark=args.mark,
|
||||||
problem='some of the required keys are missing: {0}'.format(list_sep.join(required_args - present_args))
|
problem='some of the required keys are missing: {0}'.format(list_sep.join(required_args - present_args))
|
||||||
)
|
)
|
||||||
hadproblem = True
|
hadproblem = True
|
||||||
|
|
||||||
if not all_args >= present_args:
|
if not all_args >= present_args:
|
||||||
echoerr(context='Error while checking segment arguments (key {key})'.format(key=context_key(context)),
|
echoerr(context='Error while checking segment arguments (key {key})'.format(key=context.key),
|
||||||
context_mark=args.mark,
|
context_mark=args.mark,
|
||||||
problem='found unknown keys: {0}'.format(list_sep.join(present_args - all_args)),
|
problem='found unknown keys: {0}'.format(list_sep.join(present_args - all_args)),
|
||||||
problem_mark=next(iter(present_args - all_args)).mark)
|
problem_mark=next(iter(present_args - all_args)).mark)
|
||||||
@ -642,7 +639,6 @@ def check_args_variant(func, args, data, context, echoerr):
|
|||||||
|
|
||||||
|
|
||||||
def check_args(get_functions, args, data, context, echoerr):
|
def check_args(get_functions, args, data, context, echoerr):
|
||||||
context_has_marks(context)
|
|
||||||
new_echoerr = DelayedEchoErr(echoerr)
|
new_echoerr = DelayedEchoErr(echoerr)
|
||||||
count = 0
|
count = 0
|
||||||
hadproblem = False
|
hadproblem = False
|
||||||
@ -657,7 +653,7 @@ def check_args(get_functions, args, data, context, echoerr):
|
|||||||
if new_echoerr:
|
if new_echoerr:
|
||||||
new_echoerr.echo_all()
|
new_echoerr.echo_all()
|
||||||
else:
|
else:
|
||||||
echoerr(context='Error while checking segment arguments (key {key})'.format(key=context_key(context)),
|
echoerr(context='Error while checking segment arguments (key {key})'.format(key=context.key),
|
||||||
context_mark=context[-2][1].mark,
|
context_mark=context[-2][1].mark,
|
||||||
problem='no suitable segments found')
|
problem='no suitable segments found')
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import itertools
|
|||||||
|
|
||||||
from powerline.lib.unicode import unicode
|
from powerline.lib.unicode import unicode
|
||||||
from powerline.lint.markedjson.markedvalue import MarkedUnicode
|
from powerline.lint.markedjson.markedvalue import MarkedUnicode
|
||||||
|
from powerline.lint.selfcheck import havemarks
|
||||||
|
|
||||||
|
|
||||||
class JStr(unicode):
|
class JStr(unicode):
|
||||||
@ -16,14 +17,6 @@ key_sep = JStr('/')
|
|||||||
list_sep = JStr(', ')
|
list_sep = JStr(', ')
|
||||||
|
|
||||||
|
|
||||||
def context_key(context):
|
|
||||||
return key_sep.join((c[0] for c in context))
|
|
||||||
|
|
||||||
|
|
||||||
def init_context(config):
|
|
||||||
return ((MarkedUnicode('', config.mark), config),)
|
|
||||||
|
|
||||||
|
|
||||||
def new_context_item(key, value):
|
def new_context_item(key, value):
|
||||||
return ((value.keydict[key], value[key]),)
|
return ((value.keydict[key], value[key]),)
|
||||||
|
|
||||||
@ -42,3 +35,23 @@ def list_themes(data, context):
|
|||||||
return [(ext, theme) for theme in data['ext_theme_configs'].values()]
|
return [(ext, theme) for theme in data['ext_theme_configs'].values()]
|
||||||
else:
|
else:
|
||||||
return [(ext, context[0][1])]
|
return [(ext, context[0][1])]
|
||||||
|
|
||||||
|
|
||||||
|
class Context(tuple):
|
||||||
|
def __new__(cls, base, other=None):
|
||||||
|
if other is not None:
|
||||||
|
return tuple.__new__(cls, tuple.__add__(base, other))
|
||||||
|
else:
|
||||||
|
return tuple.__new__(cls, ((MarkedUnicode('', base.mark), base),))
|
||||||
|
|
||||||
|
def __add__(self, arg):
|
||||||
|
assert(len(arg) == 1)
|
||||||
|
assert(type(arg) is tuple)
|
||||||
|
assert(len(arg[0]) == 2)
|
||||||
|
assert(type(arg[0]) is tuple)
|
||||||
|
havemarks(arg[0][0], arg[0][1])
|
||||||
|
return Context.__new__(Context, self, arg)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def key(self):
|
||||||
|
return key_sep.join((c[0] for c in self))
|
||||||
|
@ -3,8 +3,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from powerline.lint.selfcheck import havemarks, context_has_marks
|
from powerline.lint.selfcheck import havemarks
|
||||||
from powerline.lint.context import context_key
|
|
||||||
|
|
||||||
|
|
||||||
class WithPath(object):
|
class WithPath(object):
|
||||||
@ -20,26 +19,25 @@ class WithPath(object):
|
|||||||
|
|
||||||
|
|
||||||
def import_function(function_type, name, data, context, echoerr, module):
|
def import_function(function_type, name, data, context, echoerr, module):
|
||||||
context_has_marks(context)
|
|
||||||
havemarks(name, module)
|
havemarks(name, module)
|
||||||
|
|
||||||
with WithPath(data['import_paths']):
|
with WithPath(data['import_paths']):
|
||||||
try:
|
try:
|
||||||
func = getattr(__import__(str(module), fromlist=[str(name)]), str(name))
|
func = getattr(__import__(str(module), fromlist=[str(name)]), str(name))
|
||||||
except ImportError:
|
except ImportError:
|
||||||
echoerr(context='Error while checking segments (key {key})'.format(key=context_key(context)),
|
echoerr(context='Error while checking segments (key {key})'.format(key=context.key),
|
||||||
context_mark=name.mark,
|
context_mark=name.mark,
|
||||||
problem='failed to import module {0}'.format(module),
|
problem='failed to import module {0}'.format(module),
|
||||||
problem_mark=module.mark)
|
problem_mark=module.mark)
|
||||||
return None
|
return None
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
echoerr(context='Error while loading {0} function (key {key})'.format(function_type, key=context_key(context)),
|
echoerr(context='Error while loading {0} function (key {key})'.format(function_type, key=context.key),
|
||||||
problem='failed to load function {0} from module {1}'.format(name, module),
|
problem='failed to load function {0} from module {1}'.format(name, module),
|
||||||
problem_mark=name.mark)
|
problem_mark=name.mark)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not callable(func):
|
if not callable(func):
|
||||||
echoerr(context='Error while checking segments (key {key})'.format(key=context_key(context)),
|
echoerr(context='Error while checking segments (key {key})'.format(key=context.key),
|
||||||
context_mark=name.mark,
|
context_mark=name.mark,
|
||||||
problem='imported "function" {0} from module {1} is not callable'.format(name, module),
|
problem='imported "function" {0} from module {1} is not callable'.format(name, module),
|
||||||
problem_mark=module.mark)
|
problem_mark=module.mark)
|
||||||
|
@ -14,9 +14,3 @@ def havemarks(*args, **kwargs):
|
|||||||
havemarks(key, val, origin=(origin + '[' + unicode(i) + ']/' + unicode(key)))
|
havemarks(key, val, origin=(origin + '[' + unicode(i) + ']/' + unicode(key)))
|
||||||
elif isinstance(v, list):
|
elif isinstance(v, list):
|
||||||
havemarks(*v, origin=(origin + '[' + unicode(i) + ']'))
|
havemarks(*v, origin=(origin + '[' + unicode(i) + ']'))
|
||||||
|
|
||||||
|
|
||||||
def context_has_marks(context):
|
|
||||||
for i, v in enumerate(context):
|
|
||||||
havemarks(v[0], origin='context key')
|
|
||||||
havemarks(v[1], origin='context val')
|
|
||||||
|
@ -10,7 +10,7 @@ from powerline.lib.unicode import unicode
|
|||||||
from powerline.lint.markedjson.error import echoerr, DelayedEchoErr
|
from powerline.lint.markedjson.error import echoerr, DelayedEchoErr
|
||||||
from powerline.lint.markedjson.markedvalue import MarkedUnicode
|
from powerline.lint.markedjson.markedvalue import MarkedUnicode
|
||||||
from powerline.lint.selfcheck import havemarks
|
from powerline.lint.selfcheck import havemarks
|
||||||
from powerline.lint.context import context_key, list_sep, new_context_item
|
from powerline.lint.context import list_sep, new_context_item
|
||||||
|
|
||||||
|
|
||||||
class Spec(object):
|
class Spec(object):
|
||||||
@ -74,7 +74,7 @@ class Spec(object):
|
|||||||
havemarks(value)
|
havemarks(value)
|
||||||
if type(value.value) not in types:
|
if type(value.value) not in types:
|
||||||
echoerr(
|
echoerr(
|
||||||
context=self.cmsg.format(key=context_key(context)),
|
context=self.cmsg.format(key=context.key),
|
||||||
context_mark=context_mark,
|
context_mark=context_mark,
|
||||||
problem='{0!r} must be a {1} instance, not {2}'.format(
|
problem='{0!r} must be a {1} instance, not {2}'.format(
|
||||||
value,
|
value,
|
||||||
@ -90,7 +90,7 @@ class Spec(object):
|
|||||||
havemarks(value)
|
havemarks(value)
|
||||||
proceed, echo, hadproblem = func(value, data, context, echoerr)
|
proceed, echo, hadproblem = func(value, data, context, echoerr)
|
||||||
if echo and hadproblem:
|
if echo and hadproblem:
|
||||||
echoerr(context=self.cmsg.format(key=context_key(context)),
|
echoerr(context=self.cmsg.format(key=context.key),
|
||||||
context_mark=context_mark,
|
context_mark=context_mark,
|
||||||
problem=msg_func(value),
|
problem=msg_func(value),
|
||||||
problem_mark=value.mark)
|
problem_mark=value.mark)
|
||||||
@ -114,7 +114,7 @@ class Spec(object):
|
|||||||
else:
|
else:
|
||||||
proceed, echo, fhadproblem = item_func(item, data, context, echoerr)
|
proceed, echo, fhadproblem = item_func(item, data, context, echoerr)
|
||||||
if echo and fhadproblem:
|
if echo and fhadproblem:
|
||||||
echoerr(context=self.cmsg.format(key=context_key(context) + '/list item ' + unicode(i)),
|
echoerr(context=self.cmsg.format(key=context.key + '/list item ' + unicode(i)),
|
||||||
context_mark=value.mark,
|
context_mark=value.mark,
|
||||||
problem=msg_func(item),
|
problem=msg_func(item),
|
||||||
problem_mark=item.mark)
|
problem_mark=item.mark)
|
||||||
@ -332,7 +332,7 @@ class Spec(object):
|
|||||||
else:
|
else:
|
||||||
if not valspec.isoptional:
|
if not valspec.isoptional:
|
||||||
hadproblem = True
|
hadproblem = True
|
||||||
echoerr(context=self.cmsg.format(key=context_key(context)),
|
echoerr(context=self.cmsg.format(key=context.key),
|
||||||
context_mark=None,
|
context_mark=None,
|
||||||
problem='required key is missing: {0}'.format(key),
|
problem='required key is missing: {0}'.format(key),
|
||||||
problem_mark=value.mark)
|
problem_mark=value.mark)
|
||||||
@ -362,7 +362,7 @@ class Spec(object):
|
|||||||
else:
|
else:
|
||||||
hadproblem = True
|
hadproblem = True
|
||||||
if self.ufailmsg:
|
if self.ufailmsg:
|
||||||
echoerr(context=self.cmsg.format(key=context_key(context)),
|
echoerr(context=self.cmsg.format(key=context.key),
|
||||||
context_mark=None,
|
context_mark=None,
|
||||||
problem=self.ufailmsg(key),
|
problem=self.ufailmsg(key),
|
||||||
problem_mark=key.mark)
|
problem_mark=key.mark)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user