code: def fetch_bucket_contents_to_tmp_dir(bucket: str) -> str:
      tmpdir = tempfile.mkdtemp(prefix="tune_cloud_test")
      subfolder = None
  
      if bucket.startswith("s3://"):
          subprocess.check_call(
              [
                  "aws",
                  "s3",
                  "cp",
                  "--recursive",
                  "--quiet",
                  bucket,
                  tmpdir,
              ]
          )
      elif bucket.startswith("gs://"):
          try:
              subprocess.check_call(
                  ["gsutil", "-m", "cp", "-r", bucket, tmpdir]
              )
          except subprocess.CalledProcessError as e:
              # Sometimes single files cannot be processed
              if len(os.listdir(tmpdir)) == 0:
                  raise RuntimeError(
                      f"Local dir {tmpdir} empty after trying to fetch bucket data."
                  ) from e
          pattern = re.compile("gs://[^/]+/(.+)")
          subfolder = re.match(pattern, bucket).group(1).split("/")[-1]
      else:
          raise ValueError(f"Invalid bucket URL: {bucket}")
  
      if subfolder:
          tmpdir = os.path.join(tmpdir, subfolder)
  
      print("Copied bucket data from", bucket, "to", tmpdir)
  
      return tmpdir
  
imports: import argparse
  import csv
  import io
  import tarfile
  from dataclasses import dataclass
  import json
  import os
  import pickle
  import platform
  import re
  import shutil
  import signal
  import subprocess
  import tempfile
  import time
  from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple
  import ray
  from ray.train._internal.storage import StorageContext
  from ray.tune.execution.experiment_state import _find_newest_experiment_checkpoint
  from ray.tune.result import _get_defaults_results_dir
  from ray.tune.utils.serialization import TuneFunctionDecoder
label_desc: Use image node_id 16 for calling a global function with example usage: fetch_bucket_contents_to_tmp_dir(bucket) and returns: tmpdir