code: def _find_references_with_glob(
      folder: epath.Path,
      is_data_dir: bool,
      is_dataset_dir: bool,
      namespace: Optional[str] = None,
      include_old_tfds_version: bool = True,
  ) -> Iterator[naming.DatasetReference]:
      """Yields all dataset references in the given folder.
  
      Args:
        folder: the folder where to look for datasets. Can be either a root data
          dir, or a dataset folder.
        is_data_dir: Whether `folder` is a root TFDS data dir.
        is_dataset_dir: Whether `folder` is the folder of one specific dataset.
        namespace: Optional namespace to which the found datasets belong to.
        include_old_tfds_version: include datasets that have been generated with
          TFDS before 4.0.0.
  
      Yields:
        all dataset references in the given folder.
      """
      if is_dataset_dir and is_data_dir:
          raise ValueError(
              "Folder cannot be both a data dir and dataset dir!"
          )
      if not is_data_dir and not is_dataset_dir:
          raise ValueError(
              "Folder must be either a data dir or a dataset dir!"
          )
  
      if is_data_dir:
          data_dir = folder
          dataset_name = None
          globs = ["*/*/*/*.json", "*/*/*.json"]
      else:
          data_dir = folder.parent
          dataset_name = folder.name
          globs = ["*/*/*.json", "*/*.json"]
  
      # Check files matching the globs and are files we are interested in.
      matched_files_per_folder = collections.defaultdict(set)
      file_names = [
          constants.FEATURES_FILENAME,
          constants.DATASET_INFO_FILENAME,
      ]
      for file in _find_files_with_glob(
          folder, globs=globs, file_names=file_names
      ):
          matched_files_per_folder[file.parent].add(file.name)
  
      for (
          data_folder,
          matched_files,
      ) in matched_files_per_folder.items():
          if constants.DATASET_INFO_FILENAME not in matched_files:
              logging.warning(
                  "Ignoring dataset folder %s, which has no dataset_info.json",
                  os.fspath(data_folder),
              )
              continue
          if (
              not include_old_tfds_version
              and constants.FEATURES_FILENAME not in matched_files
          ):
              logging.info(
                  "Ignoring dataset folder %s, which has no features.json",
                  os.fspath(data_folder),
              )
              continue
  
          version = data_folder.name
          if not version_lib.Version.is_valid(version):
              logging.warning(
                  "Ignoring dataset folder %s, which has invalid version %s",
                  os.fspath(data_folder),
                  version,
              )
              continue
  
          config = None
          if is_data_dir:
              if data_folder.parent.parent == folder:
                  dataset_name = data_folder.parent.name
              elif data_folder.parent.parent.parent == folder:
                  dataset_name = data_folder.parent.parent.name
                  config = data_folder.parent.name
              else:
                  raise ValueError(
                      f"Could not detect dataset and config from path {data_folder} in"
                      f" {folder}"
                  )
          else:
              if data_folder.parent != folder:
                  config = data_folder.parent.name
  
          if not naming.is_valid_dataset_name(dataset_name):
              logging.warning("Invalid dataset name: %s", dataset_name)
              continue
  
          yield naming.DatasetReference(
              namespace=namespace,
              data_dir=data_dir,
              dataset_name=dataset_name,
              config=config,
              version=version,
          )
  
imports: import collections
  import functools
  import os
  import re
  import time
  from typing import Iterator, List, Optional
  from absl import logging
  from etils import epath
  from tensorflow_datasets.core import constants
  from tensorflow_datasets.core import naming
  from tensorflow_datasets.core.utils import docs
  from tensorflow_datasets.core.utils import py_utils
  from tensorflow_datasets.core.utils import read_config
  from tensorflow_datasets.core.utils import type_utils
  from tensorflow_datasets.core.utils import version
label_desc: Use image node_id 8 for calling a global function with example usage: _find_references_with_glob(folder, is_data_dir, is_dataset_dir, namespace, include_old_tfds_version) without return types