code: def resolve_path(path, ds=None, ds_resolved=None):
      """Resolve a path specification (against a Dataset location)
  
      Any path is returned as an absolute path. If, and only if, a dataset
      object instance is given as `ds`, relative paths are interpreted as
      relative to the given dataset. In all other cases, relative paths are
      treated as relative to the current working directory.
  
      Note however, that this function is not able to resolve arbitrarily
      obfuscated path specifications. All operations are purely lexical, and no
      actual path resolution against the filesystem content is performed.
      Consequently, common relative path arguments like '../something' (relative
      to PWD) can be handled properly, but things like 'down/../under' cannot, as
      resolving this path properly depends on the actual target of any
      (potential) symlink leading up to '..'.
  
      Parameters
      ----------
      path : str or PathLike or list
        Platform-specific path specific path specification. Multiple path
        specifications can be given as a list
      ds : Dataset or PathLike or None
        Dataset instance to resolve relative paths against.
      ds_resolved : Dataset or None
        A dataset instance that was created from `ds` outside can be provided
        to avoid multiple instantiation on repeated calls.
  
      Returns
      -------
      `pathlib.Path` object or list(Path)
        When a list was given as input a list is returned, a Path instance
        otherwise.
      """
      got_ds_instance = isinstance(ds, Dataset)
      if ds is not None and not got_ds_instance:
          ds = ds_resolved or require_dataset(
              ds, check_installed=False, purpose="path resolution"
          )
      out = []
      pwd_parts = None  # get it upon first use but only once
      for p in ensure_list(path):
          if ds is None or not got_ds_instance:
              # no dataset at all or no instance provided -> CWD is always the reference
              # nothing needs to be done here. Path-conversion and absolutification
              # are done next
              pass
          # we have a given datasets instance
          elif not Path(p).is_absolute():
              # we have a dataset and no abspath nor an explicit relative path ->
              # resolve it against the dataset
              p = ds.pathobj / p
  
          p = ut.Path(p)
  
          # make sure we return an absolute path, but without actually
          # resolving anything
          if not p.is_absolute():
              # in general it is almost impossible to use resolve() when
              # we can have symlinks in the root path of a dataset
              # (that we don't want to resolve here), symlinks to annex'ed
              # files (that we never want to resolve), and other within-repo
              # symlinks that we (sometimes) want to resolve (i.e. symlinked
              # paths for addressing content vs adding content)
              # CONCEPT: do the minimal thing to catch most real-world inputs
              # ASSUMPTION: the only sane relative path input that needs
              # handling and can be handled are upward references like
              # '../../some/that', whereas stuff like 'down/../someotherdown'
              # are intellectual exercises
              # ALGORITHM: match any number of leading '..' path components
              # and shorten the PWD by that number
              # NOT using ut.Path.cwd(), because it has symlinks resolved!!
              if not pwd_parts:
                  pwd_parts = ut.Path(getpwd()).parts
              path_parts = p.parts
              leading_parents = 0
              for pp in p.parts:
                  if pp == op.pardir:
                      leading_parents += 1
                      path_parts = path_parts[1:]
                  elif pp == op.curdir:
                      # we want to discard that, but without stripping
                      # a corresponding parent
                      path_parts = path_parts[1:]
                  else:
                      break
              p = ut.Path(
                  op.join(
                      *(
                          pwd_parts[
                              : -leading_parents
                              if leading_parents
                              else None
                          ]
                          + path_parts
                      )
                  )
              )
          # note that we will not "normpath()" the result, check the
          # pathlib docs for why this is the only sane choice in the
          # face of the possibility of symlinks in the path
          out.append(p)
      return out[0] if isinstance(path, (str, PurePath)) else out
  
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 3 for calling a global function with example usage: resolve_path(path, ds, ds_resolved) and returns: unknown