class_docstr: Run a command or Python code on the dataset and/or each of its sub-datasets.
  
  This command provides a convenience for the cases were no dedicated DataLad command
  is provided to operate across the hierarchy of datasets. It is very similar to
  `git submodule foreach` command with the following major differences
  
  - by default (unless [CMD: --subdatasets-only CMD][PY: `subdatasets_only=True` PY]) it would
    include operation on the original dataset as well,
  - subdatasets could be traversed in bottom-up order,
  - can execute commands in parallel (see `jobs` option), but would account for the order,
    e.g. in bottom-up order command is executed in super-dataset only after it is executed
    in all subdatasets.
  
  Additional notes:
  
  - for execution of "external" commands we use the environment used to execute external
    git and git-annex commands.
  
  *Command format*
  
  || REFLOW >>
  [CMD: --cmd-type external CMD][PY: cmd_type='external' PY]: A few placeholders are
  supported in the command via Python format specification:
  << REFLOW ||
  
  
  - "{pwd}" will be replaced with the full path of the current working directory.
  - "{ds}" and "{refds}" will provide instances of the dataset currently
    operated on and the reference "context" dataset which was provided via ``dataset``
    argument.
  - "{tmpdir}" will be replaced with the full path of a temporary directory.
class_docstr_tok: ["Run","a","command","or","Python","code","on","the","dataset","and\/or","each","of","its","sub-datasets",".","This","command","provides","a","convenience","for","the","cases","were","no","dedicated","DataLad","command","is","provided","to","operate","across","the","hierarchy","of","datasets",".","It","is","very","similar","to","`","git","submodule","foreach","`","command","with","the","following","major","differences","-","by","default","(","unless","[","CMD",":","--","subdatasets-only","CMD","]","[","PY",":","`","subdatasets_only=True","`","PY","]",")","it","would","include","operation","on","the","original","dataset","as","well",",","-","subdatasets","could","be","traversed","in","bottom-up","order",",","-","can","execute","commands","in","parallel","(","see","`","jobs","`","option",")",",","but","would","account","for","the","order",",","e.g",".","in","bottom-up","order","command","is","executed","in","super-dataset","only","after","it","is","executed","in","all","subdatasets",".","Additional","notes",":","-","for","execution","of","``","external","''","commands","we","use","the","environment","used","to","execute","external","git","and","git-annex","commands",".","*","Command","format","*","||","REFLOW",">",">","[","CMD",":","--","cmd-type","external","CMD","]","[","PY",":","cmd_type='external","'","PY","]",":","A","few","placeholders","are","supported","in","the","command","via","Python","format","specification",":","<","<","REFLOW","||","-","``","{","pwd","}","''","will","be","replaced","with","the","full","path","of","the","current","working","directory",".","-","``","{","ds","}","''","and","``","{","refds","}","''","will","provide","instances","of","the","dataset","currently","operated","on","and","the","reference","``","context","''","dataset","which","was","provided","via","``","dataset","``","argument",".","-","``","{","tmpdir","}","''","will","be","replaced","with","the","full","path","of","a","temporary","directory","."]
code: def custom_result_renderer(res, **kwargs):
      from datalad.interface.utils import generic_result_renderer
  
      if kwargs.get("output_streams") == "relpath":
          from datalad.log import no_progress
  
          with no_progress():
              ds: Union[str, Dataset] = kwargs.get("dataset")
              if ds:
                  if not isinstance(ds, Dataset):
                      ds = Dataset(ds)  # so all ///, ^ etc get treated
                  refpath = ds.path
              else:
                  refpath = getpwd()
              for k in ("stdout", "stderr"):
                  v = res.get(k)
                  if v:
                      path = res.get("path")
                      relpath = (
                          op.relpath(path, refpath) if path else ""
                      )
                      if relpath == op.curdir:
                          relpath = ""
                      if relpath and not relpath.endswith(op.sep):
                          relpath += op.sep
                      out = getattr(sys, k)
                      for l in v.splitlines():
                          out.write(f"{relpath}{l}\n")
      else:
          generic_result_renderer(res)
  
imports: import inspect
  import logging
  import os.path
  import sys
  from typing import Union
  from argparse import REMAINDER
  from itertools import chain
  from tempfile import mkdtemp
  from datalad.cmd import NoCapture, StdOutErrCapture
  from datalad.core.local.run import normalize_command
  from datalad.distribution.dataset import Dataset, EnsureDataset, datasetmethod, require_dataset
  from datalad.interface.base import Interface, build_doc, eval_results
  from datalad.interface.common_opts import contains, dataset_state, jobs_opt, recursion_flag, recursion_limit
  from datalad.interface.results import get_status_dict
  from datalad.support.constraints import EnsureBool, EnsureChoice, EnsureNone
  from datalad.support.exceptions import InsufficientArgumentsError
  from datalad.support.parallel import ProducerConsumer, ProducerConsumerProgressLog, no_parentds_in_futures, no_subds_in_futures
  from datalad.support.param import Parameter
  from datalad.utils import SequenceFormatter, chpwd, getpwd, nothing_cm, shortened_repr, swallow_outputs
label_desc: Use image node_id 2 for calling the ForEachDataset obj's underlying member method code with example usage: obj.custom_result_renderer(res) without return types