class_docstr: Patches KubeflowDagRunner.run() with several customizations for CLI.
class_docstr_tok: ["Patches","KubeflowDagRunner.run","(",")","with","several","customizations","for","CLI","."]
code: def _before_run(
      self,
      runner: tfx_runner.TfxRunner,
      pipeline: tfx_pipeline.Pipeline,
      context: MutableMapping[str, Any],
  ) -> None:
      runner = typing.cast(
          kubeflow_dag_runner.KubeflowDagRunner, runner
      )
      runner_config = typing.cast(
          kubeflow_dag_runner.KubeflowDagRunnerConfig, runner.config
      )
      if self._build_image_fn is not None:
          # Replace the image for the pipeline with the newly built image name.
          # This new image name will include the sha256 image id.
          runner_config.tfx_image = self._build_image_fn(
              runner_config.tfx_image
          )
  
      # pylint: disable=protected-access
      context[self.USE_TEMPORARY_OUTPUT_FILE] = (
          runner._output_filename is None
          and self._use_temporary_output_file
      )
      if context[self.USE_TEMPORARY_OUTPUT_FILE]:
          # Replace the output of the kfp compile to a temporary file.
          # This file will be deleted after job submission in kubeflow_handler.py
          runner._output_filename = _get_temporary_package_filename(
              context[self.PIPELINE_NAME], runner._output_dir
          )
      output_filename = (
          runner._output_filename
          or kubeflow_dag_runner.get_default_output_filename(
              context[self.PIPELINE_NAME]
          )
      )
      context[self.OUTPUT_FILE_PATH] = os.path.join(
          runner._output_dir, output_filename
      )
  
file_path: tfx/tfx/tools/cli/handler/kubeflow_dag_runner_patcher.py
imports: import os
  import tempfile
  import typing
  from typing import Any, Callable, MutableMapping, Optional, Type
  from tfx.orchestration import pipeline
  from tfx.orchestration import tfx_runner
  from tfx.orchestration.kubeflow import kubeflow_dag_runner
  from tfx.tools.cli.handler import dag_runner_patcher
label_desc: Use image node_id 2 for calling the KubeflowDagRunnerPatcher obj's underlying member method code with example usage: obj._before_run(runner, pipeline, context) without return types