How to use the peru.async_helpers.run_task function in peru

To help you get started, we’ve selected a few peru examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github buildinspace / peru / tests / test_scope.py View on Github external
def test_parse_target(self):
        scope = scope_tree_to_scope({
            'modules': {
                'a': {
                    'modules': {
                        'b': {
                            'modules': {
                                'c': {}
                            },
                            'rules': ['r'],
                        }
                    }
                }
            }
        })
        c, (r, ) = run_task(scope.parse_target(DummyRuntime(), 'a.b.c|a.b.r'))
        assert type(c) is DummyModule and c.name == 'a.b.c'
        assert type(r) is DummyRule and r.name == 'a.b.r'
github buildinspace / peru / tests / shared.py View on Github external
def wrapper(*args, **kwargs):
        return run_task(f(*args, **kwargs))
github buildinspace / peru / tests / test_plugins.py View on Github external
def test_plugin_get_reup_fields(context, type, fields):
    handle = TestDisplayHandle()
    return run_task(
        plugin.plugin_get_reup_fields(context, type, fields, handle))
github buildinspace / peru / peru / main.py View on Github external
args = docopt_parse_args(argv)
    command = args['']

    ret = maybe_print_help_and_return(args)
    if ret is not None:
        return ret

    try:
        runtime = run_task(Runtime(args, env))
        if not args['--quiet']:
            parser.warn_duplicate_keys(runtime.peru_file)
        scope, imports = parser.parse_file(runtime.peru_file)
        params = CommandParams(args, runtime, scope, imports)
        command_fn = COMMAND_FNS[command]
        run_task(command_fn(params))
    except PrintableError as e:
        if args['--verbose'] or nocatch:
            # Just allow the stacktrace to print if verbose, or in testing.
            raise
        print_red(e.message, end='' if e.message.endswith('\n') else '\n')
        return 1
github buildinspace / peru / peru / main.py View on Github external
force_utf8_in_ascii_mode_hack()

    if argv is None:
        argv = sys.argv[1:]
    if env is None:
        env = os.environ.copy()

    args = docopt_parse_args(argv)
    command = args['']

    ret = maybe_print_help_and_return(args)
    if ret is not None:
        return ret

    try:
        runtime = run_task(Runtime(args, env))
        if not args['--quiet']:
            parser.warn_duplicate_keys(runtime.peru_file)
        scope, imports = parser.parse_file(runtime.peru_file)
        params = CommandParams(args, runtime, scope, imports)
        command_fn = COMMAND_FNS[command]
        run_task(command_fn(params))
    except PrintableError as e:
        if args['--verbose'] or nocatch:
            # Just allow the stacktrace to print if verbose, or in testing.
            raise
        print_red(e.message, end='' if e.message.endswith('\n') else '\n')
        return 1