code: def _expand_directory(
      path: str,
      filesystem: "pyarrow.fs.FileSystem",
      exclude_prefixes: Optional[List[str]] = None,
      ignore_missing_path: bool = False,
  ) -> List[Tuple[str, int]]:
      """
      Expand the provided directory path to a list of file paths.
  
      Args:
          path: The directory path to expand.
          filesystem: The filesystem implementation that should be used for
              reading these files.
          exclude_prefixes: The file relative path prefixes that should be
              excluded from the returned file set. Default excluded prefixes are
              "." and "_".
  
      Returns:
          An iterator of (file_path, file_size) tuples.
      """
      if exclude_prefixes is None:
          exclude_prefixes = [".", "_"]
  
      from pyarrow.fs import FileSelector
  
      selector = FileSelector(
          path, recursive=True, allow_not_found=ignore_missing_path
      )
      files = filesystem.get_file_info(selector)
      base_path = selector.base_dir
      out = []
      for file_ in files:
          if not file_.is_file:
              continue
          file_path = file_.path
          if not file_path.startswith(base_path):
              continue
          relative = file_path[len(base_path) :]
          if any(
              relative.startswith(prefix) for prefix in exclude_prefixes
          ):
              continue
          out.append((file_path, file_.size))
      # We sort the paths to guarantee a stable order.
      return sorted(out)
  
imports: import itertools
  import logging
  import os
  import pathlib
  import re
  from typing import TYPE_CHECKING, Any, Callable, Iterator, List, Optional, Tuple, TypeVar, Union
  import numpy
  from ray.data._internal.progress_bar import ProgressBar
  from ray.data._internal.remote_fn import cached_remote_fn
  from ray.data.block import BlockMetadata
  from ray.data.datasource.partitioning import Partitioning
  from ray.util.annotations import DeveloperAPI
label_desc: Use image node_id 8 for calling a global function with example usage: _expand_directory(path, filesystem, exclude_prefixes, ignore_missing_path) and returns: sorted