code: def update_docstring_with_parameters(
      func, params, prefix=None, suffix=None, add_args=None
  ):
      """Generate a useful docstring from a parameter spec
  
      Amends any existing docstring of a callable with a textual
      description of its parameters. The Parameter spec needs to match
      the number and names of the callables arguments.
      """
      from datalad.utils import getargspec
  
      # get the signature
      args, varargs, varkw, defaults = getargspec(
          func, include_kwonlyargs=True
      )
      defaults = defaults or tuple()
      if add_args:
          add_argnames = sorted(add_args.keys())
          args.extend(add_argnames)
          defaults = defaults + tuple(add_args[k] for k in add_argnames)
      ndefaults = len(defaults)
      # start documentation with what the callable brings with it
      doc = prefix if prefix else ""
      if len(args) > 1:
          if len(doc):
              if not doc.endswith("\n"):
                  doc += "\n"
              doc += "\n"
          doc += "Parameters\n----------\n"
          for i, arg in enumerate(args):
              if not is_api_arg(arg):
                  continue
              # we need a parameter spec for each argument
              if not arg in params:
                  raise ValueError(
                      "function has argument '%s' not described as a parameter"
                      % arg
                  )
              param = params[arg]
              # validate the default -- to make sure that the parameter description is
              # somewhat OK
              defaults_idx = ndefaults - len(args) + i
              if defaults_idx >= 0:
                  if param.constraints is not None:
                      param.constraints(defaults[defaults_idx])
              orig_docs = param._doc
              param._doc = alter_interface_docs_for_api(param._doc)
              doc += param.get_autodoc(
                  arg,
                  default=defaults[defaults_idx]
                  if defaults_idx >= 0
                  else None,
                  has_default=defaults_idx >= 0,
              )
              param._doc = orig_docs
              doc += "\n"
      doc += suffix if suffix else ""
      # assign the amended docs
      func.__doc__ = doc
      return func
  
imports: import inspect
  import logging
  import os
  import re
  import textwrap
  import warnings
  from abc import ABC, abstractmethod
  from functools import wraps
  from importlib import import_module
  from typing import Callable, Dict, Generator, TypeVar, TYPE_CHECKING
  import datalad
  from datalad import cfg
  from datalad.core.local.resulthooks import get_jsonhooks_from_config, match_jsonhook2result, run_jsonhook
  from datalad.distribution.dataset import Dataset, resolve_path
  from datalad.interface.common_opts import eval_params
  from datalad.interface.results import known_result_xfms
  from datalad.interface.utils import get_result_filter, keep_result, render_action_summary, xfm_result, _process_results
  from datalad.support.exceptions import CapturedException, IncompleteResultsError
  from datalad.utils import get_wrapped_class
label_desc: Use image node_id 9 for calling a global function with example usage: update_docstring_with_parameters(func, params, prefix, suffix, add_args) and returns: func