code: def _extract_dirs_to_delete(
      executor: concurrent.futures.ThreadPoolExecutor,
      curr_dir: pathlib.Path,
      curr_tree: TreeDict,
  ) -> TaskResult:
      """Tasks which compute the directories to keep and delete.
  
      This recursively computes `listdir()` on the `curr_dir`, and compares with
      `curr_tree` to check which directory to delete. Recursion is done on the
      remaining sub-directory (cleanup `data_dir/...`, then `data_dir/mnist/...`,
      ...)
  
      Args:
        executor: Executor to launch subtasks
        curr_dir: Current directory to explore
        curr_tree: Current tree containing the name of folders to keep
  
      Returns:
        The dataclass containing files to keep, delete and sub-tasks
      """
      # End recursion with tree leafs (`.../1.2.0/`)
      if not curr_tree:
          return TaskResult(
              to_keep=[curr_dir],
              to_delete=[],
              sub_tasks=[],
          )
  
      # Compute the list of dirs to keep and delete.
      all_files = set(tf.io.gfile.listdir(str(curr_dir)))
      all_dirs_to_keep = set(curr_tree)
      dirs_to_delete = all_files - all_dirs_to_keep - DIRS_TO_KEEP
      dirs_to_maybe_keep = all_files & all_dirs_to_keep
  
      # Recurse on sub-dirs (e.g. `ds/config/`), add the dirs to the task queue.
      sub_tasks = [
          executor.submit(  # pylint: disable=g-complex-comprehension
              _extract_dirs_to_delete,
              executor=executor,
              curr_dir=curr_dir / dir_name,
              curr_tree=curr_tree[dir_name],
          )
          for dir_name in dirs_to_maybe_keep
      ]
      return TaskResult(
          to_keep=[],
          to_delete=[curr_dir / d for d in dirs_to_delete],
          sub_tasks=sub_tasks,
      )
  
file_path: datasets/tensorflow_datasets/scripts/cleanup/delete_old_versions.py
imports: import collections
  import concurrent.futures
  import dataclasses
  import os
  import pathlib
  from typing import Dict, Iterable, List, Tuple
  from absl import app
  from absl import flags
  import tensorflow_datasets
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  import termcolor
label_desc: Use image node_id 3 for calling a global function with example usage: _extract_dirs_to_delete(executor, curr_dir, curr_tree) and returns: TaskResult, TaskResult