code: def buildapi(rout):
      rout, wrap = func2subr.assubr(rout)
      args, depargs = getargs2(rout)
      capi_maps.depargs = depargs
      var = rout["vars"]
  
      if ismoduleroutine(rout):
          outmess(
              '\t\t\tConstructing wrapper function "%s.%s"...\n'
              % (rout["modulename"], rout["name"])
          )
      else:
          outmess(
              '\t\tConstructing wrapper function "%s"...\n'
              % (rout["name"])
          )
      # Routine
      vrd = capi_maps.routsign2map(rout)
      rd = dictappend({}, vrd)
      for r in rout_rules:
          if ("_check" in r and r["_check"](rout)) or (
              "_check" not in r
          ):
              ar = applyrules(r, vrd, rout)
              rd = dictappend(rd, ar)
  
      # Args
      nth, nthk = 0, 0
      savevrd = {}
      for a in args:
          vrd = capi_maps.sign2map(a, var[a])
          if isintent_aux(var[a]):
              _rules = aux_rules
          else:
              _rules = arg_rules
              if not isintent_hide(var[a]):
                  if not isoptional(var[a]):
                      nth = nth + 1
                      vrd["nth"] = (
                          repr(nth) + stnd[nth % 10] + " argument"
                      )
                  else:
                      nthk = nthk + 1
                      vrd["nth"] = (
                          repr(nthk) + stnd[nthk % 10] + " keyword"
                      )
              else:
                  vrd["nth"] = "hidden"
          savevrd[a] = vrd
          for r in _rules:
              if "_depend" in r:
                  continue
              if ("_check" in r and r["_check"](var[a])) or (
                  "_check" not in r
              ):
                  ar = applyrules(r, vrd, var[a])
                  rd = dictappend(rd, ar)
                  if "_break" in r:
                      break
      for a in depargs:
          if isintent_aux(var[a]):
              _rules = aux_rules
          else:
              _rules = arg_rules
          vrd = savevrd[a]
          for r in _rules:
              if "_depend" not in r:
                  continue
              if ("_check" in r and r["_check"](var[a])) or (
                  "_check" not in r
              ):
                  ar = applyrules(r, vrd, var[a])
                  rd = dictappend(rd, ar)
                  if "_break" in r:
                      break
          if "check" in var[a]:
              for c in var[a]["check"]:
                  vrd["check"] = c
                  ar = applyrules(check_rules, vrd, var[a])
                  rd = dictappend(rd, ar)
      if isinstance(rd["cleanupfrompyobj"], list):
          rd["cleanupfrompyobj"].reverse()
      if isinstance(rd["closepyobjfrom"], list):
          rd["closepyobjfrom"].reverse()
      rd["docsignature"] = stripcomma(
          replace(
              "#docsign##docsignopt##docsignxa#",
              {
                  "docsign": rd["docsign"],
                  "docsignopt": rd["docsignopt"],
                  "docsignxa": rd["docsignxa"],
              },
          )
      )
      optargs = stripcomma(
          replace(
              "#docsignopt##docsignxa#",
              {
                  "docsignxa": rd["docsignxashort"],
                  "docsignopt": rd["docsignoptshort"],
              },
          )
      )
      if optargs == "":
          rd["docsignatureshort"] = stripcomma(
              replace("#docsign#", {"docsign": rd["docsign"]})
          )
      else:
          rd["docsignatureshort"] = replace(
              "#docsign#[#docsignopt#]",
              {
                  "docsign": rd["docsign"],
                  "docsignopt": optargs,
              },
          )
      rd["latexdocsignatureshort"] = rd["docsignatureshort"].replace(
          "_", "\\_"
      )
      rd["latexdocsignatureshort"] = rd[
          "latexdocsignatureshort"
      ].replace(",", ", ")
      cfs = stripcomma(
          replace(
              "#callfortran##callfortranappend#",
              {
                  "callfortran": rd["callfortran"],
                  "callfortranappend": rd["callfortranappend"],
              },
          )
      )
      if len(rd["callfortranappend"]) > 1:
          rd["callcompaqfortran"] = stripcomma(
              replace(
                  "#callfortran# 0,#callfortranappend#",
                  {
                      "callfortran": rd["callfortran"],
                      "callfortranappend": rd["callfortranappend"],
                  },
              )
          )
      else:
          rd["callcompaqfortran"] = cfs
      rd["callfortran"] = cfs
      if isinstance(rd["docreturn"], list):
          rd["docreturn"] = (
              stripcomma(
                  replace("#docreturn#", {"docreturn": rd["docreturn"]})
              )
              + " = "
          )
      rd["docstrsigns"] = []
      rd["latexdocstrsigns"] = []
      for k in ["docstrreq", "docstropt", "docstrout", "docstrcbs"]:
          if k in rd and isinstance(rd[k], list):
              rd["docstrsigns"] = rd["docstrsigns"] + rd[k]
          k = "latex" + k
          if k in rd and isinstance(rd[k], list):
              rd["latexdocstrsigns"] = (
                  rd["latexdocstrsigns"]
                  + rd[k][0:1]
                  + ["\\begin{description}"]
                  + rd[k][1:]
                  + ["\\end{description}"]
              )
  
      # Workaround for Python 2.6, 2.6.1 bug: https://bugs.python.org/issue4720
      if rd["keyformat"] or rd["xaformat"]:
          argformat = rd["argformat"]
          if isinstance(argformat, list):
              argformat.append("|")
          else:
              assert isinstance(argformat, str), repr(
                  (argformat, type(argformat))
              )
              rd["argformat"] += "|"
  
      ar = applyrules(routine_rules, rd)
      if ismoduleroutine(rout):
          outmess("\t\t\t  %s\n" % (ar["docshort"]))
      else:
          outmess("\t\t  %s\n" % (ar["docshort"]))
      return ar, wrap
  
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 2 for calling a global function with example usage: buildapi(rout) and returns: ar,  wrap