code: def copy(
      src,
      dst,
      only_update=False,
      copystat=True,
      cwd=None,
      dest_is_dir=False,
      create_dest_dirs=False,
  ):
      """Variation of ``shutil.copy`` with extra options.
  
      Parameters
      ==========
  
      src : str
          Path to source file.
      dst : str
          Path to destination.
      only_update : bool
          Only copy if source is newer than destination
          (returns None if it was newer), default: ``False``.
      copystat : bool
          See ``shutil.copystat``. default: ``True``.
      cwd : str
          Path to working directory (root of relative paths).
      dest_is_dir : bool
          Ensures that dst is treated as a directory. default: ``False``
      create_dest_dirs : bool
          Creates directories if needed.
  
      Returns
      =======
  
      Path to the copied file.
  
      """
      if cwd:  # Handle working directory
          if not os.path.isabs(src):
              src = os.path.join(cwd, src)
          if not os.path.isabs(dst):
              dst = os.path.join(cwd, dst)
  
      if not os.path.exists(src):  # Make sure source file extists
          raise FileNotFoundError(
              "Source: `{}` does not exist".format(src)
          )
  
      # We accept both (re)naming destination file _or_
      # passing a (possible non-existent) destination directory
      if dest_is_dir:
          if not dst[-1] == "/":
              dst = dst + "/"
      else:
          if os.path.exists(dst) and os.path.isdir(dst):
              dest_is_dir = True
  
      if dest_is_dir:
          dest_dir = dst
          dest_fname = os.path.basename(src)
          dst = os.path.join(dest_dir, dest_fname)
      else:
          dest_dir = os.path.dirname(dst)
  
      if not os.path.exists(dest_dir):
          if create_dest_dirs:
              make_dirs(dest_dir)
          else:
              raise FileNotFoundError(
                  "You must create directory first."
              )
  
      if only_update:
          if not missing_or_other_newer(dst, src):
              return
  
      if os.path.islink(dst):
          dst = os.path.abspath(os.path.realpath(dst), cwd=cwd)
  
      shutil.copy(src, dst)
      if copystat:
          shutil.copystat(src, dst)
  
      return dst
  
imports: from collections import namedtuple
  from hashlib import sha256
  import os
  import shutil
  import sys
  import fnmatch
  from sympy.testing.pytest import XFAIL
label_desc: Use image node_id 5 for calling a global function with example usage: copy(src, dst, only_update, copystat, cwd, dest_is_dir, create_dest_dirs) and returns: dst