code: def generate_proto_files(
      force=True, output_dir=DEFAULT_PYTHON_OUTPUT_PATH
  ):
      try:
          import grpc_tools  # noqa  # pylint: disable=unused-import
      except ImportError:
          warnings.warn(
              "Installing grpcio-tools is recommended for development."
          )
  
      proto_dirs = [
          os.path.join(PYFLINK_ROOT_PATH, path) for path in PROTO_PATHS
      ]
      proto_files = sum(
          [glob.glob(os.path.join(d, "*.proto")) for d in proto_dirs],
          [],
      )
      out_dir = os.path.join(PYFLINK_ROOT_PATH, output_dir)
      out_files = [
          path for path in glob.glob(os.path.join(out_dir, "*_pb2.py*"))
      ]
  
      if out_files and not proto_files and not force:
          # We have out_files but no protos; assume they're up to date.
          # This is actually the common case (e.g. installation from an sdist).
          logging.info(
              "No proto files; using existing generated files."
          )
          return
  
      elif not out_files and not proto_files:
          raise RuntimeError("No proto files found in %s." % proto_dirs)
  
      # Regenerate iff the proto files or this file are newer.
      elif (
          force
          or not out_files
          or len(out_files) < len(proto_files)
          or (
              min(os.path.getmtime(path) for path in out_files)
              <= max(
                  os.path.getmtime(path)
                  for path in proto_files + [os.path.realpath(__file__)]
              )
          )
      ):
          try:
              from grpc_tools import protoc
          except ImportError:
              if platform.system() == "Windows":
                  # For Windows, grpcio-tools has to be installed manually.
                  raise RuntimeError(
                      "Cannot generate protos for Windows since grpcio-tools package is "
                      "not installed. Please install this package manually "
                      "using 'pip install \"grpcio-tools>=1.29.0,<=1.50.0\"'."
                  )
  
              # Use a subprocess to avoid messing with this process' path and imports.
              # Note that this requires a separate module from setup.py for Windows:
              # https://docs.python.org/2/library/multiprocessing.html#windows
              p = multiprocessing.Process(
                  target=_install_grpcio_tools_and_generate_proto_files(
                      force, output_dir
                  )
              )
              p.start()
              p.join()
              if p.exitcode:
                  raise ValueError(
                      "Proto generation failed (see log for details)."
                  )
          else:
              _check_grpcio_tools_version()
              logging.info(
                  "Regenerating out-of-date Python proto definitions."
              )
              builtin_protos = pkg_resources.resource_filename(
                  "grpc_tools", "_proto"
              )
              args = (
                  [sys.executable]
                  + [  # expecting to be called from command line
                      "--proto_path=%s" % builtin_protos
                  ]
                  + ["--proto_path=%s" % d for d in proto_dirs]
                  + ["--python_out=%s" % out_dir]
                  + ["--pyi_out=%s" % out_dir]
                  + proto_files
              )
              ret_code = protoc.main(args)
              if ret_code:
                  raise RuntimeError(
                      "Protoc returned non-zero status (see logs for details): "
                      "%s" % ret_code
                  )
  
              for output_file in os.listdir(output_dir):
                  if output_file.endswith(
                      "_pb2.py"
                  ) or output_file.endswith("_pb2.pyi"):
                      _add_license_header(output_dir, output_file)
  
file_path: flink/flink-python/pyflink/gen_protos.py
imports: from __future__ import absolute_import
  from __future__ import print_function
  import glob
  import logging
  import multiprocessing
  import os
  import platform
  import shutil
  import subprocess
  import sys
  import time
  import warnings
  import pkg_resources
label_desc: Use image node_id 1 for calling a global function with example usage: generate_proto_files(force, output_dir) without return types