code: def write_metadata(
      *,
      data_dir: epath.PathLike,
      features: features_lib.feature.FeatureConnectorArg,
      split_infos: Union[
          None, epath.PathLike, Sequence[split_lib.SplitInfo]
      ] = None,
      version: Union[None, str, utils.Version] = None,
      filename_template: Union[
          None, str, naming.ShardedFileTemplate
      ] = None,
      check_data: bool = True,
      **ds_info_kwargs,
  ) -> None:
      """Add metadata required to load with TFDS.
  
      See documentation for usage:
      https://www.tensorflow.org/datasets/external_tfrecord
  
      Args:
        data_dir: Dataset path on which to save the metadata
        features: dict of `tfds.features.FeatureConnector` matching the proto specs.
        split_infos: Can be either:  * A path to the pre-computed split info values
          ( the `out_dir` kwarg of `tfds.folder_dataset.compute_split_info`) * A
          list of `tfds.core.SplitInfo` (returned value of
          `tfds.folder_dataset.compute_split_info`) * `None` to auto-compute the
          split info.
        version: Optional dataset version (auto-infer by default, or fallback to
          1.0.0)
        filename_template: the template for the filenames of the data. If None, then
          the default template `'{DATASET}-{SPLIT}.{FILEFORMAT}-{SHARD_X_OF_Y}'` is
          used. A string or a ShardedFileTemplate can be given for custom templates.
        check_data: If True, perform additional check to validate the data in
          data_dir is valid
        **ds_info_kwargs: Additional metadata forwarded to `tfds.core.DatasetInfo` (
          description, homepage,...). Will appear in the doc.
      """
      filename_template = _construct_filename_template(
          data_dir=data_dir, filename_template=filename_template
      )
      file_infos = _get_file_infos(filename_template=filename_template)
      filename_template = _enrich_filename_template(
          filename_template, file_infos
      )
  
      if version is None:  # Automatically detect the version
          if utils.Version.is_valid(filename_template.data_dir.name):
              version = filename_template.data_dir.name
          else:
              version = "1.0.0"
  
      dataset_identity = dataset_info.DatasetIdentity(
          name=filename_template.dataset_name,
          version=utils.Version(version),
          data_dir=os.fspath(filename_template.data_dir),
          module_name="",
      )
  
      # Create the metadata
      features = features_lib.features_dict.to_feature(features)
      ds_info = dataset_info.DatasetInfo(
          builder=dataset_identity,
          features=features,
          **ds_info_kwargs,
      )
      file_format = file_adapters.file_format_from_suffix(
          filename_template.filetype_suffix
      )
      ds_info.set_file_format(file_format)
  
      # Add the split infos
      split_dict = _load_splits(
          split_infos=split_infos,
          file_infos=file_infos,
          filename_template=filename_template,
      )
      ds_info.set_splits(split_dict)
  
      # Save all metadata (dataset_info.json, features.json,...)
      ds_info.write_to_directory(data_dir)
  
      # Make sure that the data can be loaded (feature connector matches the actual
      # specs)
      if check_data:
          utils.print_notebook(
              "Metadata written. Testing by reading first example. "
              "Set check_data=False to skip."
          )
          builder = read_only_builder.builder_from_directory(data_dir)
          split_name = next(iter(builder.info.splits))
          (_,) = builder.as_dataset(split=f"{split_name}[:1]")
  
file_path: datasets/tensorflow_datasets/core/folder_dataset/write_metadata_utils.py
imports: from collections.abc import Sequence
  import os
  from typing import Union
  from etils import epath
  from tensorflow_datasets.core import dataset_info
  from tensorflow_datasets.core import features
  from tensorflow_datasets.core import file_adapters
  from tensorflow_datasets.core import naming
  from tensorflow_datasets.core import read_only_builder
  from tensorflow_datasets.core import splits
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.folder_dataset import compute_split_utils
label_desc: Use image node_id 4 for calling a global function with example usage: write_metadata() without return types