code: def require_dataset(dataset, check_installed=True, purpose=None):
      """Helper function to resolve a dataset.
  
      This function tries to resolve a dataset given an input argument,
      or based on the process' working directory, if `None` is given.
  
      Parameters
      ----------
      dataset : None or path or Dataset
        Some value identifying a dataset or `None`. In the latter case
        a dataset will be searched based on the process working directory.
      check_installed : bool, optional
        If True, an optional check whether the resolved dataset is
        properly installed will be performed.
      purpose : str, optional
        This string will be inserted in error messages to make them more
        informative. The pattern is "... dataset for <STRING>".
  
      Returns
      -------
      Dataset
        If a dataset could be determined.
  
      Raises
      ------
      NoDatasetFound
        If not dataset could be determined.
      """
      if dataset is not None and not isinstance(dataset, Dataset):
          dataset = Dataset(dataset)
  
      if dataset is None:  # possible scenario of cmdline calls
          dspath = get_dataset_root(getpwd())
          if not dspath:
              raise NoDatasetFound(
                  "No dataset found at '{}'{}.  Specify a dataset to work with "
                  "by providing its path via the `dataset` option, "
                  "or change the current working directory to be in a "
                  "dataset.".format(
                      getpwd(),
                      " for the purpose {!r}".format(purpose)
                      if purpose
                      else "",
                  )
              )
          dataset = Dataset(dspath)
  
      assert dataset is not None
      lgr.debug(
          "Resolved dataset%s: %s",
          " to {}".format(purpose) if purpose else "",
          dataset.path,
      )
  
      if check_installed and not dataset.is_installed():
          raise NoDatasetFound(
              f"No installed dataset found at {dataset.path}"
          )
  
      return dataset
  
imports: import inspect
  import logging
  from functools import wraps
  from os.path import curdir, exists, join, normpath, pardir
  from weakref import WeakValueDictionary
  from datalad import cfg
  from datalad.config import ConfigManager
  from datalad.core.local.repo import repo_from_path
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.constraints import Constraint
  from datalad.support.due import due
  from datalad.support.due_utils import duecredit_dataset
  from datalad.support.exceptions import NoDatasetFound
  from datalad.dataset.repo import path_based_str_repr, PathBasedFlyweight
  from datalad.support.gitrepo import GitRepo
  from datalad.support import path
  import datalad.utils
  from datalad.utils import getpwd, optional_args, get_dataset_root, get_sig_param_names, get_dataset_root, Path, PurePath, ensure_list
label_desc: Use image node_id 2 for calling a global function with example usage: require_dataset(dataset, check_installed, purpose) and returns: dataset