class_docstr: Clean up after DataLad (possible temporary files etc.)
  
  Removes temporary files and directories left behind by DataLad and
  git-annex in a dataset.
class_docstr_tok: ["Clean","up","after","DataLad","(","possible","temporary","files","etc",".",")","Removes","temporary","files","and","directories","left","behind","by","DataLad","and","git-annex","in","a","dataset","."]
code: def __call__(
      *,
      dataset=None,
      what=None,
      dry_run=False,
      recursive=False,
      recursion_limit=None,
  ):
      ds = require_dataset(
          dataset,
          purpose="report on cleanable locations"
          if dry_run
          else "clean dataset",
      )
      res_kwargs = dict(
          action="clean [dry-run]" if dry_run else "clean",
          logger=lgr,
          refds=ds.path,
      )
      for wds in itertools.chain(
          [ds],
          ds.subdatasets(
              state="present",
              recursive=recursive,
              recursion_limit=recursion_limit,
              return_type="generator",
              result_renderer="disabled",
              result_xfm="datasets",
          )
          if recursive
          else [],
      ):
          d = wds.pathobj
          gitdir = wds.repo.dot_git
          DIRS_PLURAL = ("directory", "directories")
          FILES_PLURAL = ("file", "files")
          discover_or_remove = "Discovered" if dry_run else "Removed"
  
          for dirpath, flag, msg, sing_pl in [
              (
                  Path(ARCHIVES_TEMP_DIR),
                  "cached-archives",
                  "temporary archive",
                  DIRS_PLURAL,
              ),
              (
                  Path(ANNEX_TEMP_DIR),
                  "annex-tmp",
                  "temporary annex",
                  FILES_PLURAL,
              ),
              (
                  Path(ANNEX_TRANSFER_DIR),
                  "annex-transfer",
                  "annex temporary transfer",
                  DIRS_PLURAL,
              ),
              (
                  gitdir / Path(SEARCH_INDEX_DOTGITDIR),
                  "search-index",
                  "metadata search index",
                  FILES_PLURAL,
              ),
          ]:
              topdir = wds.pathobj / dirpath
              lgr.debug("Considering to clean %s:%s", d, dirpath)
              if not ((what is None) or (flag in what)):
                  yield get_status_dict(
                      path=str(topdir),
                      status="notneeded",
                      type="directory",
                      **res_kwargs,
                  )
                  continue
  
              paths = [p for p in topdir.glob("*")]
              if not paths:
                  if not topdir.exists():
                      yield get_status_dict(
                          path=str(topdir),
                          status="notneeded",
                          type="directory",
                          **res_kwargs,
                      )
                      continue
                  else:
                      # we empty topdir only
                      message = (
                          "%s empty %s directory",
                          discover_or_remove,
                          msg,
                      )
              else:
                  pl = len(paths) > 1
                  message = (
                      "%s %d %s %s: %s",
                      discover_or_remove,
                      len(paths),
                      msg,
                      sing_pl[int(pl)],
                      ", ".join(
                          sorted(
                              [
                                  str(p.relative_to(topdir))
                                  for p in paths
                                  if p != topdir
                              ]
                          )
                      ),
                  )
  
              if not dry_run:
                  rmtree(str(topdir))
  
              yield get_status_dict(
                  path=str(topdir),
                  status="ok",
                  type="directory",
                  message=message,
                  **res_kwargs,
              )
  
file_path: datalad/datalad/local/clean.py
imports: import itertools
  from logging import getLogger
  from datalad.consts import ANNEX_TEMP_DIR, ANNEX_TRANSFER_DIR, ARCHIVES_TEMP_DIR, SEARCH_INDEX_DOTGITDIR
  from datalad.distribution.dataset import EnsureDataset, datasetmethod, require_dataset
  from datalad.interface.base import Interface, build_doc, eval_results
  from datalad.interface.common_opts import recursion_flag, recursion_limit
  from datalad.interface.results import get_status_dict
  from datalad.support.constraints import EnsureChoice, EnsureNone
  from datalad.support.param import Parameter
  from datalad.utils import Path, rmtree
label_desc: Use image node_id 1 for calling the Clean obj's underlying member method code with example usage: obj.__call__() without return types