MCPcopy
hub / github.com/powerline/powerline / import_function

Function import_function

powerline/lint/imp.py:21–52  ·  view source on GitHub ↗
(function_type, name, data, context, echoerr, module)

Source from the content-addressed store, hash-verified

19
20
21def import_function(function_type, name, data, context, echoerr, module):
22 havemarks(name, module)
23
24 if module == 'powerline.segments.i3wm' and name == 'workspaces':
25 echoerr(context='Warning while checking segments (key {key})'.format(key=context.key),
26 context_mark=name.mark,
27 problem='segment {0} from {1} is deprecated'.format(name, module),
28 problem_mark=module.mark)
29
30 with WithPath(data['import_paths']):
31 try:
32 func = getattr(__import__(str(module), fromlist=[str(name)]), str(name))
33 except ImportError:
34 echoerr(context='Error while checking segments (key {key})'.format(key=context.key),
35 context_mark=name.mark,
36 problem='failed to import module {0}'.format(module),
37 problem_mark=module.mark)
38 return None
39 except AttributeError:
40 echoerr(context='Error while loading {0} function (key {key})'.format(function_type, key=context.key),
41 problem='failed to load function {0} from module {1}'.format(name, module),
42 problem_mark=name.mark)
43 return None
44
45 if not callable(func):
46 echoerr(context='Error while checking segments (key {key})'.format(key=context.key),
47 context_mark=name.mark,
48 problem='imported “function” {0} from module {1} is not callable'.format(name, module),
49 problem_mark=module.mark)
50 return None
51
52 return func
53
54
55def import_segment(*args, **kwargs):

Callers 2

check_exinclude_functionFunction · 0.90
import_segmentFunction · 0.85

Calls 3

havemarksFunction · 0.90
echoerrFunction · 0.85
WithPathClass · 0.85

Tested by

no test coverage detected