Ejemplo n.º 1
0
def MC(methods, kwargs, firstresult=False):
    caller = _multicall
    hookfuncs = []
    for method in methods:
        f = HookImpl(None, "<temp>", method, method.example_impl)
        hookfuncs.append(f)
    return caller("foo", hookfuncs, kwargs, firstresult)
Ejemplo n.º 2
0
 def wrap(func):
     example_implementation(
         tryfirst=tryfirst, trylast=trylast, hookwrapper=hookwrapper
     )(func)
     hook_caller._add_hookimpl(
         HookImpl(None, "<temp>", func, func.example_impl)
     )
     return func
Ejemplo n.º 3
0
def MC(methods, kwargs, firstresult=False):
    caller = _multicall
    hookfuncs = []
    for method in methods:
        f = HookImpl(None, "<temp>", method, method.example_impl)
        hookfuncs.append(f)
        if "__multicall__" in f.argnames:
            caller = _legacymulticall
    return caller(hookfuncs, kwargs, firstresult=firstresult)
Ejemplo n.º 4
0
 def setup():
     hook_name = "foo"
     hook_impls = []
     for method in hooks + wrappers:
         f = HookImpl(None, "<temp>", method, method.example_impl)
         hook_impls.append(f)
     caller_kwargs = {"arg1": 1, "arg2": 2, "arg3": 3}
     firstresult = False
     return (hook_name, hook_impls, caller_kwargs, firstresult), {}
Ejemplo n.º 5
0
def multicall(methods, kwargs, firstresult=False):
    """utility function to execute the hook implementations loop"""
    caller = _hook_callers._multicall
    hookfuncs = []
    for method in methods:
        f = HookImpl(None, "<temp>", method, method.example_impl)
        hookfuncs.append(f)
    # our _multicall function returns our own HookResult object.
    # so to make these pluggy tests pass, we have to access .result to mimic
    # the old behavior (that directly returns results).
    return caller(hookfuncs, kwargs, firstresult=firstresult).result
Ejemplo n.º 6
0
 def inner(func,
           specname,
           tryfirst=True,
           trylast=None,
           plugin_name="<temp>"):
     caller = getattr(plugin_manager.hook, specname)
     # HookimplMarker creates a decorator.
     # And when we call it on func it just sets an attribute on func
     HookimplMarker('napari')(tryfirst=tryfirst, trylast=trylast)(func)
     impl = HookImpl(None, plugin_name, func, func.napari_impl)
     caller._add_hookimpl(impl)
     try:
         yield
     finally:
         if impl in caller._nonwrappers:
             caller._nonwrappers.remove(impl)
         if impl in caller._wrappers:
             caller._wrappers.remove(impl)
         assert impl not in caller.get_hookimpls()
Ejemplo n.º 7
0
def MC(methods, kwargs, callertype, firstresult=False):
    hookfuncs = []
    for method in methods:
        f = HookImpl(None, "<temp>", method, method.example_impl)
        hookfuncs.append(f)
    return callertype(hookfuncs, kwargs, {"firstresult": firstresult})
Ejemplo n.º 8
0
 def wrap(func):
     hookimpl(tryfirst=tryfirst,
              trylast=trylast,
              hookwrapper=hookwrapper)(func)
     hc._add_hookimpl(HookImpl(None, "<temp>", func, func.example_impl))
     return func