code: def main(argv):
      """
      Validates the docstrings of all the pre decided set of
      modules for errors and docstring standards.
      """
      parser = ArgumentParser(usage=__doc__.lstrip())
      parser.add_argument(
          "module_names",
          metavar="SUBMODULES",
          default=[],
          nargs="*",
          help="Submodules to check (default: all public)",
      )
      parser.add_argument(
          "--doctests",
          action="store_true",
          help="Run also doctests on ",
      )
      parser.add_argument("-v", "--verbose", action="count", default=0)
      parser.add_argument(
          "--doctest-warnings",
          action="store_true",
          help="Enforce warning checking for doctests",
      )
      parser.add_argument(
          "--rst",
          nargs="?",
          const="doc",
          default=None,
          help=(
              "Run also examples from *rst files "
              "discovered walking the directory(s) specified, "
              "defaults to 'doc'"
          ),
      )
      args = parser.parse_args(argv)
  
      modules = []
      names_dict = {}
  
      if not args.module_names:
          args.module_names = list(PUBLIC_SUBMODULES) + [BASE_MODULE]
  
      os.environ["SCIPY_PIL_IMAGE_VIEWER"] = "true"
  
      module_names = list(args.module_names)
      for name in module_names:
          if name in OTHER_MODULE_DOCS:
              name = OTHER_MODULE_DOCS[name]
              if name not in module_names:
                  module_names.append(name)
  
      dots = True
      success = True
      results = []
      errormsgs = []
  
      if args.doctests or args.rst:
          init_matplotlib()
  
      for submodule_name in module_names:
          prefix = BASE_MODULE + "."
          if not (
              submodule_name.startswith(prefix)
              or submodule_name == BASE_MODULE
          ):
              module_name = prefix + submodule_name
          else:
              module_name = submodule_name
  
          __import__(module_name)
          module = sys.modules[module_name]
  
          if submodule_name not in OTHER_MODULE_DOCS:
              find_names(module, names_dict)
  
          if submodule_name in args.module_names:
              modules.append(module)
  
      if args.doctests or not args.rst:
          print("Running checks for %d modules:" % (len(modules),))
          for module in modules:
              if dots:
                  sys.stderr.write(module.__name__ + " ")
                  sys.stderr.flush()
  
              all_dict, deprecated, others = get_all_dict(module)
              names = names_dict.get(module.__name__, set())
  
              mod_results = []
              mod_results += check_items(
                  all_dict, names, deprecated, others, module.__name__
              )
              mod_results += check_rest(
                  module, set(names).difference(deprecated), dots=dots
              )
              if args.doctests:
                  mod_results += check_doctests(
                      module,
                      (args.verbose >= 2),
                      dots=dots,
                      doctest_warnings=args.doctest_warnings,
                  )
  
              for v in mod_results:
                  assert isinstance(v, tuple), v
  
              results.append((module, mod_results))
  
              if dots:
                  sys.stderr.write("\n")
                  sys.stderr.flush()
  
      if args.rst:
          base_dir = os.path.join(
              os.path.abspath(os.path.dirname(__file__)), ".."
          )
          rst_path = os.path.relpath(os.path.join(base_dir, args.rst))
          if os.path.exists(rst_path):
              print("\nChecking files in %s:" % rst_path)
              check_documentation(rst_path, results, args, dots)
          else:
              sys.stderr.write(f'\ninvalid --rst argument "{args.rst}"')
              errormsgs.append("invalid directory argument to --rst")
          if dots:
              sys.stderr.write("\n")
              sys.stderr.flush()
  
      # Report results
      for module, mod_results in results:
          success = all(x[1] for x in mod_results)
          if not success:
              errormsgs.append(f"failed checking {module.__name__}")
  
          if success and args.verbose == 0:
              continue
  
          print("")
          print("=" * len(module.__name__))
          print(module.__name__)
          print("=" * len(module.__name__))
          print("")
  
          for name, success, output in mod_results:
              if name is None:
                  if not success or args.verbose >= 1:
                      print(output.strip())
                      print("")
              elif not success or (
                  args.verbose >= 2 and output.strip()
              ):
                  print(name)
                  print("-" * len(name))
                  print("")
                  print(output.strip())
                  print("")
  
      if len(errormsgs) == 0:
          print("\nOK: all checks passed!")
          sys.exit(0)
      else:
          print("\nERROR: ", "\n        ".join(errormsgs))
          sys.exit(1)
  
imports: import copy
  import doctest
  import inspect
  import io
  import os
  import re
  import shutil
  import sys
  import tempfile
  import warnings
  import docutils.core
  from argparse import ArgumentParser
  from contextlib import contextmanager, redirect_stderr
  from doctest import NORMALIZE_WHITESPACE, ELLIPSIS, IGNORE_EXCEPTION_DETAIL
  from docutils.parsers.rst import directives
  import sphinx
  import numpy
  from numpydoc.docscrape_sphinx import get_doc_object
  from sphinx.directives.other import SeeAlso, Only
label_desc: Use image node_id 16 for calling a global function with example usage: main(argv) without return types