class_docstr: Util class to build splits.
  
  Usage is as follow:
  
  ```py
  split_builder = SplitBuilder(...)
  
  with split_builder.maybe_beam_pipeline():
    split_info_future = split_builder.submit_split_generation(...)
  
  split_info = split_info_future.result()
  ```
  
  * submit_split_generation:
    * For generator based split: Generate the split
    * For Apache Beam based split: Create the `beam.PCollection` and returns
      a future.
  * `split_info_future.result()`: Called after all `beam.PCollection`s have
    finished. Finalize the `split_info` by collecting all pipeline results.
  
  `submit_split_generation` / `.result` should be called once per
  split.
class_docstr_tok: ["Util","class","to","build","splits",".","Usage","is","as","follow",":","``","`","py","split_builder","=","SplitBuilder","(","...",")","with","split_builder.maybe_beam_pipeline","(",")",":","split_info_future","=","split_builder.submit_split_generation","(","...",")","split_info","=","split_info_future.result","(",")","``","`","*","submit_split_generation",":","*","For","generator","based","split",":","Generate","the","split","*","For","Apache","Beam","based","split",":","Create","the","`","beam.PCollection","`","and","returns","a","future",".","*","`","split_info_future.result","(",")","`",":","Called","after","all","`","beam.PCollection","`","s","have","finished",".","Finalize","the","`","split_info","`","by","collecting","all","pipeline","results",".","`","submit_split_generation","`","\/","`",".result","`","should","be","called","once","per","split","."]
docstr: Context manager wrapping the beam pipeline.
  
  If Apache Beam is used, then the pipeline created withing the contextmanager
  will be launched when exiting the context manager:
  
  ```py
  with split_builder.maybe_beam_pipeline():
    pcollection = (
        split_builder.beam_pipeline
        | beam.Create()
        | beam.Map()
    )
  ```
  
  Is equivalent to:
  
  ```py
  with beam.Pipeline() as beam_pipeline:
    pcollection = (
        beam_pipeline
        | beam.Create()
        | beam.Map()
    )
  ```
  
  If `split_builder.beam_pipeline` is never called, then `beam.Pipeline` is
  never created and this function is a no-op.
  
  Yields:
    PipelineProxy containing a reference to the beam pipeline, allowing access
      to the pipeline result for (e.g) logging metrics to file.
docstr_tok: ["Context","manager","wrapping","the","beam","pipeline",".","If","Apache","Beam","is","used",",","then","the","pipeline","created","withing","the","contextmanager","will","be","launched","when","exiting","the","context","manager",":","``","`","py","with","split_builder.maybe_beam_pipeline","(",")",":","pcollection","=","(","split_builder.beam_pipeline","|","beam.Create","(",")","|","beam.Map","(",")",")","``","`","Is","equivalent","to",":","``","`","py","with","beam.Pipeline","(",")","as","beam_pipeline",":","pcollection","=","(","beam_pipeline","|","beam.Create","(",")","|","beam.Map","(",")",")","``","`","If","`","split_builder.beam_pipeline","`","is","never","called",",","then","`","beam.Pipeline","`","is","never","created","and","this","function","is","a","no-op",".","Yields",":","PipelineProxy","containing","a","reference","to","the","beam","pipeline",",","allowing","access","to","the","pipeline","result","for","(","e.g",")","logging","metrics","to","file","."]
code: def maybe_beam_pipeline(self) -> Iterator[PipelineProxy]:
      """Context manager wrapping the beam pipeline.
  
      If Apache Beam is used, then the pipeline created withing the contextmanager
      will be launched when exiting the context manager:
  
      ```py
      with split_builder.maybe_beam_pipeline():
        pcollection = (
            split_builder.beam_pipeline
            | beam.Create()
            | beam.Map()
        )
      ```
  
      Is equivalent to:
  
      ```py
      with beam.Pipeline() as beam_pipeline:
        pcollection = (
            beam_pipeline
            | beam.Create()
            | beam.Map()
        )
      ```
  
      If `split_builder.beam_pipeline` is never called, then `beam.Pipeline` is
      never created and this function is a no-op.
  
      Yields:
        PipelineProxy containing a reference to the beam pipeline, allowing access
          to the pipeline result for (e.g) logging metrics to file.
      """
      self._in_contextmanager = True
      try:
          # Entering the contextmanager is a no-op. Only if Apache Beam is used
          # is the `beam.Pipeline` contextmanager activated.
          # Construct pipeline proxy with a placeholder beam pipeline.
          pipeline_proxy = PipelineProxy(_beam_pipeline=None)
          yield pipeline_proxy
      except Exception:  # pylint: disable=broad-except
          # Close and forward the exception
          if (
              not self._beam_pipeline
              or not self._beam_pipeline.__exit__(*sys.exc_info())
          ):
              raise  # Forward the exception
      else:
          # If the Beam pipeline was used, then exit it.
          if self._beam_pipeline is not None:
              self._beam_pipeline.__exit__(None, None, None)
              # Fill in the beam pipeline in the proxy.
              pipeline_proxy._beam_pipeline = (
                  self._beam_pipeline
              )  # pylint:disable=protected-access
      self._in_contextmanager = False
  
imports: import collections.abc
  import contextlib
  import dataclasses
  import functools
  import itertools
  import sys
  from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union
  from absl import logging
  import click
  import psutil
  from tensorflow_datasets.core import example_serializer
  from tensorflow_datasets.core import features
  from tensorflow_datasets.core import file_adapters
  from tensorflow_datasets.core import naming
  from tensorflow_datasets.core import splits
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core import writer
  from tensorflow_datasets.core.utils import shard_utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import apache_beam
label_desc: Use image node_id 2 for calling the SplitBuilder obj's underlying member method code with example usage: obj.maybe_beam_pipeline() without return types