code: def clone_dataset(
      srcs,
      destds,
      reckless=None,
      description=None,
      result_props=None,
      cfg=None,
      checkout_gitsha=None,
      clone_opts=None,
  ):
      """Internal helper to perform cloning without sanity checks (assumed done)
  
      This helper does not handle any saving of subdataset modification or adding
      in a superdataset.
  
      Parameters
      ----------
      srcs : list
        Any suitable clone source specifications (paths, URLs)
      destds : Dataset
        Dataset instance for the clone destination
      reckless : {None, 'auto', 'ephemeral', 'shared-...'}, optional
        Mode switch to put cloned dataset into unsafe/throw-away configurations, i.e.
        sacrifice data safety for performance or resource footprint. When None
        and `cfg` is specified, use the value of `datalad.clone.reckless`.
      description : str, optional
        Location description for the annex of the dataset clone (if there is any).
      result_props : dict, optional
        Default properties for any yielded result, passed on to get_status_dict().
      cfg : ConfigManager, optional
        Configuration for parent dataset. This will be queried instead
        of the global DataLad configuration.
      checkout_gitsha : str, optional
        If given, a specific commit, identified by shasum, will be checked out after
        cloning. A dedicated follow-up fetch will be performed, if the initial clone
        did not obtain the commit object. Should the checkout of the target commit
        cause a detached HEAD, the previously active branch will be reset to the
        target commit.
      clone_opts : list of str, optional
        Options passed to git-clone. Note that for RIA URLs, the version is
        translated to a --branch argument, and that will take precedence over a
        --branch argument included in this value.
  
      Yields
      ------
      dict
        DataLad result records
      """
      # apply the two in-house patches, do local to avoid circular imports
      from . import (
          clone_ephemeral,
          clone_ria,
      )
  
      if not result_props:
          # in case the caller had no specific idea on how results should look
          # like, provide sensible defaults
          result_props = dict(
              action="install",
              logger=lgr,
              ds=destds,
          )
      else:
          result_props = result_props.copy()
  
      candidate_sources = _generate_candidate_clone_sources(
          destds, srcs, cfg
      )
  
      # important test!
      # based on this `rmtree` will happen below after failed clone
      dest_path_existed, stop_props = _test_existing_clone_target(
          destds, candidate_sources
      )
      if stop_props:
          # something happened that indicates we cannot continue
          # yield and return
          result_props.update(stop_props)
          yield get_status_dict(**result_props)
          return
  
      if reckless is None and cfg:
          # if reckless is not explicitly given, but we operate on a
          # superdataset, query whether it has been instructed to operate
          # in a reckless mode, and inherit it for the coming clone
          reckless = cfg.get("datalad.clone.reckless", None)
  
      last_candidate, error_msgs, stop_props = _try_clone_candidates(
          destds=destds,
          candidate_sources=candidate_sources,
          clone_opts=clone_opts or [],
          dest_path_existed=dest_path_existed,
      )
      if stop_props:
          # no luck, report and stop
          result_props.update(stop_props)
          yield get_status_dict(**result_props)
          return
      else:
          # we can record the last attempt as the candidate URL that gave
          # a successful clone
          result_props["source"] = last_candidate
  
      if not destds.is_installed():
          # we do not have a clone, stop, provide aggregate error message
          # covering all attempts
          yield get_status_dict(
              status="error",
              message=_format_clone_errors(
                  destds, error_msgs, last_candidate["giturl"]
              ),
              **result_props,
          )
          return
  
      #
      # At minimum all further processing is all candidate for extension
      # patching.  wrap the whole thing in try-except, catch any exceptions
      # report it as an error results `rmtree` any intermediate and return
      #
      try:
          yield from _post_gitclone_processing_(
              destds=destds,
              cfg=cfg,
              gitclonerec=last_candidate,
              reckless=reckless,
              checkout_gitsha=checkout_gitsha,
              description=description,
          )
      except Exception as e:
          ce = CapturedException(e)
          # the rational for turning any exception into an error result is that
          # we are hadly able to distinguish user-error from an other errors
          yield get_status_dict(
              status="error",
              # XXX A test in core insists on the wrong message type to be used
              # error_message=ce.message,
              message=ce.message,
              exception=ce,
              **result_props,
          )
          rmtree(destds.path, children_only=dest_path_existed)
          return
  
      # yield successful clone of the base dataset now, as any possible
      # subdataset clone down below will not alter the Git-state of the
      # parent
      yield get_status_dict(status="ok", **result_props)
  
imports: import logging
  from argparse import REMAINDER
  from typing import Dict
  from datalad.cmd import CommandError
  from datalad.config import ConfigManager
  from datalad.distribution.dataset import Dataset, EnsureDataset, datasetmethod, require_dataset, resolve_path
  from datalad.interface.base import Interface, build_doc, eval_results
  from datalad.interface.common_opts import location_description, reckless_opt
  from datalad.interface.results import get_status_dict
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.constraints import EnsureKeyChoice, EnsureNone, EnsureStr
  from datalad.support.exceptions import CapturedException
  from datalad.support.network import RI, PathRI
  from datalad.support.param import Parameter
  from datalad.utils import knows_annex, PurePath, rmtree
  from .clone_utils import _check_autoenable_special_remotes, _format_clone_errors, _generate_candidate_clone_sources, _get_remote, _get_tracking_source, _map_urls, _test_existing_clone_target, _try_clone_candidates, decode_source_spec, postclone_preannex_cfg_ria, postclonecfg_ria
label_desc: Use image node_id 1 for calling a global function with example usage: clone_dataset(srcs, destds, reckless, description, result_props, cfg, checkout_gitsha, clone_opts) without return types