code: def create_modules_toc_file(
      modules: list[str],
      opts: Any,
      name: str = "modules",
      user_template_dir: str | None = None,
  ) -> None:
      """Create the module's index."""
      modules.sort()
      prev_module = ""
      for module in modules.copy():
          # look if the module is a subpackage and, if yes, ignore it
          if module.startswith(prev_module + "."):
              modules.remove(module)
          else:
              prev_module = module
  
      context = {
          "header": opts.header,
          "maxdepth": opts.maxdepth,
          "docnames": modules,
      }
      if user_template_dir is not None:
          template_path = [user_template_dir, template_dir]
      else:
          template_path = [template_dir]
      text = ReSTRenderer(template_path).render("toc.rst_t", context)
      write_file(name, text, opts)
  
imports: from __future__ import annotations
  import argparse
  import fnmatch
  import glob
  import locale
  import os
  import re
  import sys
  from copy import copy
  from importlib.machinery import EXTENSION_SUFFIXES
  from os import path
  from typing import TYPE_CHECKING, Any
  import sphinx.locale
  from sphinx import __display_version__, package_dir
  from sphinx.cmd.quickstart import EXTENSIONS
  from sphinx.locale import __
  from sphinx.util import logging
  from sphinx.util.osutil import FileAvoidWrite, ensuredir
  from sphinx.util.template import ReSTRenderer
label_desc: Use image node_id 7 for calling a global function with example usage: create_modules_toc_file(modules, opts, name, user_template_dir) without return types