code: def main():
      p = optparse.OptionParser(usage=(__doc__ or "").strip())
      p.add_option(
          "--no-force", action="store_false", dest="force", default=True
      )
      options, args = p.parse_args()
  
      names = []
  
      i_types, it_types, getter_code = get_thunk_type_set()
  
      # Generate *_impl.h for each compilation unit
      for unit_name, routines in COMPILATION_UNITS:
          thunks = []
          methods = []
  
          # Generate thunks and methods for all routines
          for line in routines.splitlines():
              line = line.strip()
              if not line or line.startswith("#"):
                  continue
  
              try:
                  name, args = line.split(None, 1)
              except ValueError:
                  raise ValueError("Malformed line: %r" % (line,))
  
              args = "".join(args.split())
              if "t" in args or "T" in args:
                  thunk, method = parse_routine(name, args, it_types)
              else:
                  thunk, method = parse_routine(name, args, i_types)
  
              if name in names:
                  raise ValueError("Duplicate routine %r" % (name,))
  
              names.append(name)
              thunks.append(thunk)
              methods.append(method)
  
          # Produce output
          dst = os.path.join(
              os.path.dirname(__file__),
              "sparsetools",
              unit_name + "_impl.h",
          )
          if newer(__file__, dst) or options.force:
              print("[generate_sparsetools] generating %r" % (dst,))
              with open(dst, "w") as f:
                  write_autogen_blurb(f)
                  f.write(getter_code)
                  for thunk in thunks:
                      f.write(thunk)
                  for method in methods:
                      f.write(method)
          else:
              print(
                  "[generate_sparsetools] %r already up-to-date"
                  % (dst,)
              )
  
      # Generate code for method struct
      method_defs = ""
      for name in names:
          method_defs += (
              "NPY_VISIBILITY_HIDDEN PyObject *%s_method(PyObject *, PyObject *);\n"
              % (name,)
          )
  
      method_struct = (
          """\nstatic struct PyMethodDef sparsetools_methods[] = {"""
      )
      for name in names:
          method_struct += """
          {"%(name)s", (PyCFunction)%(name)s_method, METH_VARARGS, NULL},""" % dict(
              name=name
          )
      method_struct += """
          {NULL, NULL, 0, NULL}
      };"""
  
      # Produce sparsetools_impl.h
      dst = os.path.join(
          os.path.dirname(__file__), "sparsetools", "sparsetools_impl.h"
      )
  
      if newer(__file__, dst) or options.force:
          print("[generate_sparsetools] generating %r" % (dst,))
          with open(dst, "w") as f:
              write_autogen_blurb(f)
              f.write(method_defs)
              f.write(method_struct)
      else:
          print("[generate_sparsetools] %r already up-to-date" % (dst,))
  
imports: import optparse
  import os
  from distutils.dep_util import newer
label_desc: Use image node_id 3 for calling a global function with example usage: main() without return types