code: def buildmodule(m, um):
      """
      Return
      """
      global f2py_version, options
      outmess('\tBuilding module "%s"...\n' % (m["name"]))
      ret = {}
      mod_rules = defmod_rules[:]
      vrd = capi_maps.modsign2map(m)
      rd = dictappend({"f2py_version": f2py_version}, vrd)
      funcwrappers = []
      funcwrappers2 = []  # F90 codes
      for n in m["interfaced"]:
          nb = None
          for bi in m["body"]:
              if not bi["block"] == "interface":
                  errmess(
                      "buildmodule: Expected interface block. Skipping.\n"
                  )
                  continue
              for b in bi["body"]:
                  if b["name"] == n:
                      nb = b
                      break
  
          if not nb:
              errmess(
                  'buildmodule: Could not found the body of interfaced routine "%s". Skipping.\n'
                  % (n)
              )
              continue
          nb_list = [nb]
          if "entry" in nb:
              for k, a in nb["entry"].items():
                  nb1 = copy.deepcopy(nb)
                  del nb1["entry"]
                  nb1["name"] = k
                  nb1["args"] = a
                  nb_list.append(nb1)
          for nb in nb_list:
              api, wrap = buildapi(nb)
              if wrap:
                  if ismoduleroutine(nb):
                      funcwrappers2.append(wrap)
                  else:
                      funcwrappers.append(wrap)
              ar = applyrules(api, vrd)
              rd = dictappend(rd, ar)
  
      # Construct COMMON block support
      cr, wrap = common_rules.buildhooks(m)
      if wrap:
          funcwrappers.append(wrap)
      ar = applyrules(cr, vrd)
      rd = dictappend(rd, ar)
  
      # Construct F90 module support
      mr, wrap = f90mod_rules.buildhooks(m)
      if wrap:
          funcwrappers2.append(wrap)
      ar = applyrules(mr, vrd)
      rd = dictappend(rd, ar)
  
      for u in um:
          ar = use_rules.buildusevars(u, m["use"][u["name"]])
          rd = dictappend(rd, ar)
  
      needs = cfuncs.get_needs()
      code = {}
      for n in needs.keys():
          code[n] = []
          for k in needs[n]:
              c = ""
              if k in cfuncs.includes0:
                  c = cfuncs.includes0[k]
              elif k in cfuncs.includes:
                  c = cfuncs.includes[k]
              elif k in cfuncs.userincludes:
                  c = cfuncs.userincludes[k]
              elif k in cfuncs.typedefs:
                  c = cfuncs.typedefs[k]
              elif k in cfuncs.typedefs_generated:
                  c = cfuncs.typedefs_generated[k]
              elif k in cfuncs.cppmacros:
                  c = cfuncs.cppmacros[k]
              elif k in cfuncs.cfuncs:
                  c = cfuncs.cfuncs[k]
              elif k in cfuncs.callbacks:
                  c = cfuncs.callbacks[k]
              elif k in cfuncs.f90modhooks:
                  c = cfuncs.f90modhooks[k]
              elif k in cfuncs.commonhooks:
                  c = cfuncs.commonhooks[k]
              else:
                  errmess("buildmodule: unknown need %s.\n" % (repr(k)))
                  continue
              code[n].append(c)
      mod_rules.append(code)
      for r in mod_rules:
          if ("_check" in r and r["_check"](m)) or ("_check" not in r):
              ar = applyrules(r, vrd, m)
              rd = dictappend(rd, ar)
      ar = applyrules(module_rules, rd)
  
      fn = os.path.join(options["buildpath"], vrd["coutput"])
      ret["csrc"] = fn
      f = open(fn, "w")
      f.write(ar["modulebody"].replace("\t", 2 * " "))
      f.close()
      outmess(
          '\tWrote C/API module "%s" to file "%s"\n' % (m["name"], fn)
      )
  
      if options["dorestdoc"]:
          fn = os.path.join(
              options["buildpath"], vrd["modulename"] + "module.rest"
          )
          f = open(fn, "w")
          f.write(".. -*- rest -*-\n")
          f.write("\n".join(ar["restdoc"]))
          f.close()
          outmess(
              '\tReST Documentation is saved to file "%s/%smodule.rest"\n'
              % (options["buildpath"], vrd["modulename"])
          )
      if options["dolatexdoc"]:
          fn = os.path.join(
              options["buildpath"], vrd["modulename"] + "module.tex"
          )
          ret["ltx"] = fn
          f = open(fn, "w")
          f.write(
              "%% This file is auto-generated with f2py (version:%s)\n"
              % (f2py_version)
          )
          if "shortlatex" not in options:
              f.write(
                  "\\documentclass{article}\n\\usepackage{a4wide}\n\\begin{document}\n\\tableofcontents\n\n"
              )
          f.write("\n".join(ar["latexdoc"]))
          if "shortlatex" not in options:
              f.write("\\end{document}")
          f.close()
          outmess(
              '\tDocumentation is saved to file "%s/%smodule.tex"\n'
              % (options["buildpath"], vrd["modulename"])
          )
      if funcwrappers:
          wn = os.path.join(
              options["buildpath"], vrd["f2py_wrapper_output"]
          )
          ret["fsrc"] = wn
          f = open(wn, "w")
          f.write("C     -*- fortran -*-\n")
          f.write(
              "C     This file is autogenerated with f2py (version:%s)\n"
              % (f2py_version)
          )
          f.write(
              "C     It contains Fortran 77 wrappers to fortran functions.\n"
          )
          lines = []
          for l in ("\n\n".join(funcwrappers) + "\n").split("\n"):
              if l and l[0] == " ":
                  while len(l) >= 66:
                      lines.append(l[:66] + "\n     &")
                      l = l[66:]
                  lines.append(l + "\n")
              else:
                  lines.append(l + "\n")
          lines = "".join(lines).replace("\n     &\n", "\n")
          f.write(lines)
          f.close()
          outmess('\tFortran 77 wrappers are saved to "%s"\n' % (wn))
      if funcwrappers2:
          wn = os.path.join(
              options["buildpath"],
              "%s-f2pywrappers2.f90" % (vrd["modulename"]),
          )
          ret["fsrc"] = wn
          f = open(wn, "w")
          f.write("!     -*- f90 -*-\n")
          f.write(
              "!     This file is autogenerated with f2py (version:%s)\n"
              % (f2py_version)
          )
          f.write(
              "!     It contains Fortran 90 wrappers to fortran functions.\n"
          )
          lines = []
          for l in ("\n\n".join(funcwrappers2) + "\n").split("\n"):
              if len(l) > 72 and l[0] == " ":
                  lines.append(l[:72] + "&\n     &")
                  l = l[72:]
                  while len(l) > 66:
                      lines.append(l[:66] + "&\n     &")
                      l = l[66:]
                  lines.append(l + "\n")
              else:
                  lines.append(l + "\n")
          lines = "".join(lines).replace("\n     &\n", "\n")
          f.write(lines)
          f.close()
          outmess('\tFortran 90 wrappers are saved to "%s"\n' % (wn))
      return ret
  
file_path: catboost/contrib/python/numpy/py2/numpy/f2py/rules.py
imports: from __future__ import division, absolute_import, print_function
  from .None import __version__
  import os
  import time
  import copy
  from .auxfuncs import applyrules, debugcapi, dictappend, errmess, gentitle, getargs2, hascallstatement, hasexternals, hasinitvalue, hasnote, hasresultnote, isarray, isarrayofstrings, iscomplex, iscomplexarray, iscomplexfunction, iscomplexfunction_warn, isdummyroutine, isexternal, isfunction, isfunction_wrap, isint1array, isintent_aux, isintent_c, isintent_callback, isintent_copy, isintent_hide, isintent_inout, isintent_nothide, isintent_out, isintent_overwrite, islogical, islong_complex, islong_double, islong_doublefunction, islong_long, islong_longfunction, ismoduleroutine, isoptional, isrequired, isscalar, issigned_long_longarray, isstring, isstringarray, isstringfunction, issubroutine, issubroutine_wrap, isthreadsafe, isunsigned, isunsigned_char, isunsigned_chararray, isunsigned_long_long, isunsigned_long_longarray, isunsigned_short, isunsigned_shortarray, l_and, l_not, l_or, outmess, replace, stripcomma
  from .None import capi_maps
  from .None import cfuncs
  from .None import common_rules
  from .None import use_rules
  from .None import f90mod_rules
  from .None import func2subr
label_desc: Use image node_id 1 for calling a global function with example usage: buildmodule(m, um) and returns: ret