code: def makepipeline(infile, steps, outfile):
      # Build a list with for each command:
      # [input filename or '', command string, kind, output filename or '']
  
      list = []
      for cmd, kind in steps:
          list.append(["", cmd, kind, ""])
      #
      # Make sure there is at least one step
      #
      if not list:
          list.append(["", "cat", "--", ""])
      #
      # Take care of the input and output ends
      #
      [cmd, kind] = list[0][1:3]
      if kind[0] == "f" and not infile:
          list.insert(0, ["", "cat", "--", ""])
      list[0][0] = infile
      #
      [cmd, kind] = list[-1][1:3]
      if kind[1] == "f" and not outfile:
          list.append(["", "cat", "--", ""])
      list[-1][-1] = outfile
      #
      # Invent temporary files to connect stages that need files
      #
      garbage = []
      for i in range(1, len(list)):
          lkind = list[i - 1][2]
          rkind = list[i][2]
          if lkind[1] == "f" or rkind[0] == "f":
              (fd, temp) = tempfile.mkstemp()
              os.close(fd)
              garbage.append(temp)
              list[i - 1][-1] = list[i][0] = temp
      #
      for item in list:
          [inf, cmd, kind, outf] = item
          if kind[1] == "f":
              cmd = "OUT=" + quote(outf) + "; " + cmd
          if kind[0] == "f":
              cmd = "IN=" + quote(inf) + "; " + cmd
          if kind[0] == "-" and inf:
              cmd = cmd + " <" + quote(inf)
          if kind[1] == "-" and outf:
              cmd = cmd + " >" + quote(outf)
          item[1] = cmd
      #
      cmdlist = list[0][1]
      for item in list[1:]:
          [cmd, kind] = item[1:3]
          if item[0] == "":
              if "f" in kind:
                  cmd = "{ " + cmd + "; }"
              cmdlist = cmdlist + " |\n" + cmd
          else:
              cmdlist = cmdlist + "\n" + cmd
      #
      if garbage:
          rmcmd = "rm -f"
          for file in garbage:
              rmcmd = rmcmd + " " + quote(file)
          trapcmd = (
              "trap " + quote(rmcmd + "; exit") + " 1 2 3 13 14 15"
          )
          cmdlist = trapcmd + "\n" + cmdlist + "\n" + rmcmd
      #
      return cmdlist
  
file_path: catboost/contrib/tools/python3/src/Lib/pipes.py
imports: import re
  import os
  import tempfile
  import warnings
  from shlex import quote
label_desc: Use image node_id 1 for calling a global function with example usage: makepipeline(infile, steps, outfile) and returns: cmdlist