code: def run_if(command, out, *prerequisites):
      """
      Runs a command only if the output file is not up to date.
  
      Args:
          command:
              The command to run. We write this into a file <out>.cmd so that we
              know to run a command if the command itself has changed.
          out:
              Path of the output file.
  
          prerequisites:
              List of prerequisite paths or true/false/None items. If an item
              is None it is ignored, otherwise if an item is not a string we
              immediately return it cast to a bool.
  
      Returns:
          True if we ran the command, otherwise None.
  
  
      If the output file does not exist, the command is run:
  
          >>> verbose(1)
          1
          >>> out = 'run_if_test_out'
          >>> if os.path.exists( out):
          ...     os.remove( out)
          >>> run_if( f'touch {out}', out)
          True
  
      If we repeat, the output file will be up to date so the command is not run:
  
          >>> run_if( f'touch {out}', out)
  
      If we change the command, the command is run:
  
          >>> run_if( f'touch  {out}', out)
          True
  
      If we add a prerequisite that is newer than the output, the command is run:
  
          >>> prerequisite = 'run_if_test_prerequisite'
          >>> run( f'touch {prerequisite}')
          >>> run_if( f'touch {out}', out, prerequisite)
          True
  
      If we repeat, the output will be newer than the prerequisite, so the
      command is not run:
  
          >>> run_if( f'touch {out}', out, prerequisite)
      """
      doit = False
      if not doit:
          out_mtime = _fs_mtime(out)
          if out_mtime == 0:
              doit = "File does not exist: {out!e}"
  
      cmd_path = f"{out}.cmd"
      if os.path.isfile(cmd_path):
          with open(cmd_path) as f:
              cmd = f.read()
      else:
          cmd = None
      if command != cmd:
          if cmd is None:
              doit = "No previous command stored"
          else:
              doit = f"Command has changed"
              if 0:
                  doit += f": {cmd!r} => {command!r}"
  
      if not doit:
          # See whether any prerequisites are newer than target.
          def _make_prerequisites(p):
              if isinstance(p, (list, tuple)):
                  return list(p)
              else:
                  return [p]
  
          prerequisites_all = list()
          for p in prerequisites:
              prerequisites_all += _make_prerequisites(p)
          if 0:
              log2("prerequisites_all:")
              for i in prerequisites_all:
                  log2(f"    {i!r}")
          pre_mtime = 0
          pre_path = None
          for prerequisite in prerequisites_all:
              if isinstance(prerequisite, str):
                  mtime = _fs_mtime_newest(prerequisite)
                  if mtime >= pre_mtime:
                      pre_mtime = mtime
                      pre_path = prerequisite
              elif prerequisite is None:
                  pass
              elif prerequisite:
                  doit = str(prerequisite)
                  break
          if not doit:
              if pre_mtime > out_mtime:
                  doit = f"Prerequisite is new: {pre_path!r}"
  
      if doit:
          # Remove `cmd_path` before we run the command, so any failure
          # will force rerun next time.
          #
          try:
              os.remove(cmd_path)
          except Exception:
              pass
          log2(f"Running command because: {doit}")
  
          run(command)
  
          # Write the command we ran, into `cmd_path`.
          with open(cmd_path, "w") as f:
              f.write(command)
          return True
      else:
          log2(f"Not running command because up to date: {out!r}")
  
      if 0:
          log2(
              f"out_mtime={time.ctime(out_mtime)} pre_mtime={time.ctime(pre_mtime)}."
              f" pre_path={pre_path!r}: returning {ret!r}."
          )
  
imports: import base64
  import glob
  import hashlib
  import inspect
  import io
  import os
  import platform
  import re
  import shutil
  import site
  import setuptools
  import subprocess
  import sys
  import sysconfig
  import tarfile
  import textwrap
  import time
  import zipfile
  import wdev
label_desc: Use image node_id 15 for calling a global function with example usage: run_if(command, out) and returns: True, list, list