(function_type, name, data, context, echoerr, module)
| 19 | |
| 20 | |
| 21 | def 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 | |
| 55 | def import_segment(*args, **kwargs): |
no test coverage detected