code: def fetch(  # noqa: PLR0913
      self,
      targets=None,
      jobs=None,
      remote=None,
      all_branches=False,
      with_deps=False,
      all_tags=False,
      recursive=False,
      all_commits=False,
      run_cache=False,
      revs=None,
      workspace=True,
      max_size=None,
      types=None,
      config=None,
      onerror=None,
  ) -> int:
      """Download data items from a cloud and imported repositories
  
      Returns:
          int: number of successfully downloaded files
  
      Raises:
          DownloadError: thrown when there are failed downloads, either
              during `cloud.pull` or trying to fetch imported files
  
          config.NoRemoteError: thrown when downloading only local files and no
              remote is configured
      """
      from fsspec.utils import tokenize
  
      from dvc_data.index.fetch import collect
      from dvc_data.index.fetch import fetch as ifetch
  
      if isinstance(targets, str):
          targets = [targets]
  
      failed_count = 0
      transferred_count = 0
  
      try:
          if run_cache:
              self.stage_cache.pull(remote)
      except DownloadError as exc:
          failed_count += exc.amount
  
      indexes = _collect_indexes(
          self,
          targets=targets,
          remote=remote,
          all_branches=all_branches,
          with_deps=with_deps,
          all_tags=all_tags,
          recursive=recursive,
          all_commits=all_commits,
          revs=revs,
          workspace=workspace,
          max_size=max_size,
          types=types,
          config=config,
          onerror=onerror,
      )
  
      cache_key = (
          "fetch",
          tokenize(
              sorted(
                  idx.data_tree.hash_info.value
                  for idx in indexes.values()
              )
          ),
      )
  
      with ui.progress(
          desc="Collecting",
          unit="entry",
          leave=True,
      ) as pb:
          data = collect(
              [idx.data["repo"] for idx in indexes.values()],
              "remote",
              cache_index=self.data_index,
              cache_key=cache_key,
              callback=pb.as_callback(),
          )
      data, unversioned_count = _log_unversioned(data)
      failed_count += unversioned_count
  
      with ui.progress(
          desc="Fetching",
          bar_format="{desc}",
          leave=True,
      ) as pb:
          try:
              fetch_transferred, fetch_failed = ifetch(
                  data,
                  jobs=jobs,
                  callback=pb.as_callback(),
              )
          finally:
              for fs_index in data:
                  fs_index.close()
  
      if fetch_transferred:
          # NOTE: dropping cached index to force reloading from newly saved cache
          self.drop_data_index()
  
      transferred_count += fetch_transferred
      failed_count += fetch_failed
      if failed_count:
          raise DownloadError(failed_count)
  
      return transferred_count
  
file_path: dvc/dvc/repo/fetch.py
imports: from typing import TYPE_CHECKING, List, Tuple
  from dvc.exceptions import DownloadError
  from dvc.log import logger
  from dvc.ui import ui
  from dvc_data.index import DataIndex, FileStorage
  from .None import locked
label_desc: Use image node_id 3 for calling a global function with example usage: fetch(targets, jobs, remote, all_branches, with_deps, all_tags, recursive, all_commits, run_cache, revs, workspace, max_size, types, config, onerror) and returns: transferred_count