code: def main(*args):
      parser = ArgumentParser(description="Update the .mailmap file")
      parser.add_argument(
          "--update-authors",
          action="store_true",
          help=filldedent(
              """
              Also updates the AUTHORS file. DO NOT use this option as part of a
              pull request. The AUTHORS file will be updated later at the time a
              new version of SymPy is released."""
          ),
      )
      args = parser.parse_args(args)
  
      if not check_git_version():
          return 1
  
      # find who git knows ahout
      try:
          git_people = get_authors_from_git()
      except AssertionError as msg:
          print(red(msg))
          return 1
  
      lines_mailmap = read_lines(mailmap_path())
  
      def key(line):
          # return lower case first address on line or
          # raise an error if not an entry
          if "#" in line:
              line = line.split("#")[0]
          L, R = line.count("<"), line.count(">")
          assert L == R and L in (1, 2)
          return line.split(">", 1)[0].split("<")[1].lower()
  
      who = OrderedDict()
      for i, line in enumerate(lines_mailmap):
          try:
              who.setdefault(key(line), []).append(line)
          except AssertionError:
              who[i] = [line]
  
      problems = False
      missing = False
      ambiguous = False
      dups = defaultdict(list)
  
      #
      # Here we use the git people with the most recent commit skipped. This
      # means we don't need to add .mailmap entries for the temporary merge
      # commit created in CI on a PR.
      #
      for person in git_people:
          email = key(person)
          dups[email].append(person)
          if email not in who:
              print(
                  red(
                      "This author is not included in the .mailmap file:"
                  )
              )
              print(person)
              missing = True
          elif not any(p.startswith(person) for p in who[email]):
              print(red("Ambiguous names in .mailmap"))
              print(
                  red(
                      "This email address appears for multiple entries:"
                  )
              )
              print("Person:", person)
              print("Mailmap entries:")
              for line in who[email]:
                  print(line)
              ambiguous = True
  
      if missing:
          print(
              red(
                  filldedent(
                      """
          The .mailmap file needs to be updated because there are commits with
          unrecognised author/email metadata.
          """
                  )
              )
          )
          problems = True
  
      if ambiguous:
          print(
              red(
                  filldedent(
                      """
          Lines should be added to .mailmap to indicate the correct name and
          email aliases for all commits.
          """
                  )
              )
          )
          problems = True
  
      for email, commitauthors in dups.items():
          if len(commitauthors) > 2:
              print(
                  red(
                      filldedent(
                          """
              The following commits are recorded with different metadata but the
              same/ambiguous email address. The .mailmap file will need to be
              updated."""
                      )
                  )
              )
              for author in commitauthors:
                  print(author)
              problems = True
  
      lines_mailmap_sorted = sort_lines_mailmap(lines_mailmap)
      write_lines(mailmap_path(), lines_mailmap_sorted)
  
      if lines_mailmap_sorted != lines_mailmap:
          problems = True
          print(red("The mailmap file was reordered"))
  
      # Check if changes to AUTHORS file are also needed
      #
      # Here we don't skip the last commit. We need authors from the most recent
      # commit if the AUTHORS file was updated.
      lines_authors = make_authors_file_lines(git_people)
      old_lines_authors = read_lines(authors_path())
  
      for person in old_lines_authors[8:]:
          if person not in git_people:
              print(
                  red(
                      "This author is in the AUTHORS file but not .mailmap:"
                  )
              )
              print(person)
              problems = True
  
      if problems:
          print(
              red(
                  filldedent(
                      """
          For instructions on updating the .mailmap file see:
  https://docs.sympy.org/dev/contributing/new-contributors-guide/workflow-process.html#mailmap-instructions""",
                      break_on_hyphens=False,
                      break_long_words=False,
                  )
              )
          )
      else:
          print(green("No changes needed in .mailmap"))
  
      # Actually update the AUTHORS file (if --update-authors was passed)
      authors_changed = update_authors_file(
          lines_authors, old_lines_authors, args.update_authors
      )
  
      return int(problems) + int(authors_changed)
  
imports: from __future__ import unicode_literals
  from __future__ import print_function
  import sys
  from pathlib import Path
  from subprocess import run, PIPE
  from collections import OrderedDict, defaultdict
  from argparse import ArgumentParser
  import sympy
  from sympy.utilities.misc import filldedent
  from sympy.external.importtools import version_tuple
label_desc: Use image node_id 2 for calling a global function with example usage: main() and returns: unknown, int, line, int