code: def test_exclusion(start_cluster, tmp_working_dir, option):
      """Tests various forms of the 'excludes' parameter."""
      cluster, address = start_cluster
  
      def create_file(p, empty=False):
          if not p.parent.exists():
              p.parent.mkdir(parents=True)
          with p.open("w") as f:
              if not empty:
                  f.write("Test")
  
      working_path = Path(tmp_working_dir)
      create_file(working_path / "__init__.py", empty=True)
      create_file(working_path / "test1")
      create_file(working_path / "test2")
      create_file(working_path / "test3")
      create_file(working_path / "tmp_dir" / "test_1")
      create_file(working_path / "tmp_dir" / "test_2")
      create_file(working_path / "tmp_dir" / "test_3")
      create_file(working_path / "tmp_dir" / "sub_dir" / "test_1")
      create_file(working_path / "tmp_dir" / "sub_dir" / "test_2")
      create_file(working_path / "cache" / "test_1")
      create_file(working_path / "tmp_dir" / "cache" / "test_1")
      create_file(working_path / "another_dir" / "cache" / "test_1")
  
      module_name = Path(tmp_working_dir).name
  
      # Test that all files are present without excluding.
      if option == "working_dir":
          ray.init(
              address, runtime_env={"working_dir": tmp_working_dir}
          )
      else:
          ray.init(
              address, runtime_env={"py_modules": [tmp_working_dir]}
          )
  
      @ray.remote
      def check_file(name):
          if option == "py_modules":
              try:
                  module = import_module(module_name)
              except ImportError:
                  return "FAILED"
              name = os.path.join(module.__path__[0], name)
          try:
              with open(name) as f:
                  return f.read()
          except Exception:
              return "FAILED"
  
      def get_all():
          return ray.get(
              [
                  check_file.remote("test1"),
                  check_file.remote("test2"),
                  check_file.remote("test3"),
                  check_file.remote(os.path.join("tmp_dir", "test_1")),
                  check_file.remote(os.path.join("tmp_dir", "test_2")),
                  check_file.remote(os.path.join("tmp_dir", "test_3")),
                  check_file.remote(
                      os.path.join("tmp_dir", "sub_dir", "test_1")
                  ),
                  check_file.remote(
                      os.path.join("tmp_dir", "sub_dir", "test_2")
                  ),
                  check_file.remote(os.path.join("cache", "test_1")),
                  check_file.remote(
                      os.path.join("tmp_dir", "cache", "test_1")
                  ),
                  check_file.remote(
                      os.path.join("another_dir", "cache", "test_1")
                  ),
              ]
          )
  
      assert get_all() == [
          "Test",
          "Test",
          "Test",
          "Test",
          "Test",
          "Test",
          "Test",
          "Test",
          "Test",
          "Test",
          "Test",
      ]
  
      ray.shutdown()
  
      # Test various exclusion methods.
      excludes = [
          # exclude by relative path
          "test2",
          # exclude by dir
          str((Path("tmp_dir") / "sub_dir").as_posix()),
          # exclude part of the dir
          str((Path("tmp_dir") / "test_1").as_posix()),
          # exclude part of the dir
          str((Path("tmp_dir") / "test_2").as_posix()),
      ]
  
      if option == "working_dir":
          ray.init(
              address,
              runtime_env={
                  "working_dir": tmp_working_dir,
                  "excludes": excludes,
              },
          )
      else:
          ray.init(
              address,
              runtime_env={
                  "py_modules": [tmp_working_dir],
                  "excludes": excludes,
              },
          )
  
      assert get_all() == [
          "Test",
          "FAILED",
          "Test",
          "FAILED",
          "FAILED",
          "Test",
          "FAILED",
          "FAILED",
          "Test",
          "Test",
          "Test",
      ]
  
      ray.shutdown()
  
      # Test excluding all files using gitignore pattern matching syntax
      excludes = ["*"]
      if option == "working_dir":
          ray.init(
              address,
              runtime_env={
                  "working_dir": tmp_working_dir,
                  "excludes": excludes,
              },
          )
      else:
          module_name = Path(tmp_working_dir).name
          ray.init(
              address,
              runtime_env={
                  "py_modules": [tmp_working_dir],
                  "excludes": excludes,
              },
          )
  
      assert get_all() == [
          "FAILED",
          "FAILED",
          "FAILED",
          "FAILED",
          "FAILED",
          "FAILED",
          "FAILED",
          "FAILED",
          "FAILED",
          "FAILED",
          "FAILED",
      ]
  
      ray.shutdown()
  
      # Test excluding with a .gitignore file.
      with open(f"{tmp_working_dir}/.gitignore", "w") as f:
          f.write(
              """
  # Comment
  test_[12]
  /test1
  !/tmp_dir/sub_dir/test_1
  cache/
  """
          )
  
      if option == "working_dir":
          ray.init(
              address, runtime_env={"working_dir": tmp_working_dir}
          )
      else:
          module_name = Path(tmp_working_dir).name
          ray.init(
              address, runtime_env={"py_modules": [tmp_working_dir]}
          )
  
      assert get_all() == [
          "FAILED",
          "Test",
          "Test",
          "FAILED",
          "FAILED",
          "Test",
          "Test",
          "FAILED",
          "FAILED",
          "FAILED",
          "FAILED",
      ]
  
imports: import os
  import shutil
  import sys
  import tempfile
  import time
  from importlib import import_module
  from pathlib import Path
  from unittest import mock
  import pytest
  import ray
  from ray._private import gcs_utils
  from ray._private.runtime_env.context import RuntimeEnvContext
  from ray._private.runtime_env.packaging import get_uri_for_directory, upload_package_if_needed
  from ray._private.runtime_env.working_dir import WorkingDirPlugin, set_pythonpath_in_context
  from ray._private.utils import get_directory_size_bytes
label_desc: Use image node_id 7 for calling a global function with example usage: test_exclusion(start_cluster, tmp_working_dir, option) and returns: ray, f, str, str