code: def delegating_hooks_method(method_name):
      """Factory function for making DelegatingHooks methods."""
      if method_name in PIPELINE_HOOKS_CONTEXT_MANAGERS:
          # Generate a contextmanager that enters the context of all child hooks.
          @wraps(getattr(PipelineHooks, method_name))
          @contextmanager
          def ctx(self, *args, **kwargs):
              with ExitStack() as stack:
                  for hook in self._hooks:
                      sub_ctx = getattr(hook, method_name)(
                          *args, **kwargs
                      )
                      stack.enter_context(sub_ctx)
                  yield stack
  
          return ctx
      else:
          # Generate a method that calls methods of all child hooks.
          @wraps(getattr(PipelineHooks, method_name))
          def method(self, *args, **kwargs):
              for hook in self._hooks:
                  sub_method = getattr(hook, method_name)
                  sub_method(*args, **kwargs)
  
          return method
  
imports: from interface import implements
  from zipline.utils.compat import ExitStack, contextmanager, wraps
  from .iface import PipelineHooks, PIPELINE_HOOKS_CONTEXT_MANAGERS
  from .no import NoHooks
label_desc: Use image node_id 1 for calling a global function with example usage: delegating_hooks_method(method_name) and returns: ctx, method