code: def prompt_loop_or_load_from_env(
      environ_cp,
      var_name,
      var_default,
      ask_for_var,
      check_success,
      error_msg,
      suppress_default_error=False,
      resolve_symlinks=False,
      n_ask_attempts=_DEFAULT_PROMPT_ASK_ATTEMPTS,
  ):
      """Loop over user prompts for an ENV param until receiving a valid response.
  
      For the env param var_name, read from the environment or verify user input
      until receiving valid input. When done, set var_name in the environ_cp to its
      new value.
  
      Args:
        environ_cp: (Dict) copy of the os.environ.
        var_name: (String) string for name of environment variable, e.g. "TF_MYVAR".
        var_default: (String) default value string.
        ask_for_var: (String) string for how to ask for user input.
        check_success: (Function) function that takes one argument and returns a
          boolean. Should return True if the value provided is considered valid. May
          contain a complex error message if error_msg does not provide enough
          information. In that case, set suppress_default_error to True.
        error_msg: (String) String with one and only one '%s'. Formatted with each
          invalid response upon check_success(input) failure.
        suppress_default_error: (Bool) Suppress the above error message in favor of
          one from the check_success function.
        resolve_symlinks: (Bool) Translate symbolic links into the real filepath.
        n_ask_attempts: (Integer) Number of times to query for valid input before
          raising an error and quitting.
  
      Returns:
        [String] The value of var_name after querying for input.
  
      Raises:
        UserInputError: if a query has been attempted n_ask_attempts times without
          success, assume that the user has made a scripting error, and will
          continue to provide invalid input. Raise the error to avoid infinitely
          looping.
      """
      default = environ_cp.get(var_name) or var_default
      full_query = "%s [Default is %s]: " % (
          ask_for_var,
          default,
      )
  
      for _ in range(n_ask_attempts):
          val = get_from_env_or_user_or_default(
              environ_cp, var_name, full_query, default
          )
          if check_success(val):
              break
          if not suppress_default_error:
              print(error_msg % val)
          environ_cp[var_name] = ""
      else:
          raise UserInputError(
              "Invalid %s setting was provided %d times in a row. "
              "Assuming to be a scripting mistake."
              % (var_name, n_ask_attempts)
          )
  
      if resolve_symlinks:
          val = os.path.realpath(val)
      environ_cp[var_name] = val
      return val
  
imports: import argparse
  import os
  import pathlib
  import platform
  import re
  import subprocess
  import sys
label_desc: Use image node_id 24 for calling a global function with example usage: prompt_loop_or_load_from_env(environ_cp, var_name, var_default, ask_for_var, check_success, error_msg, suppress_default_error, resolve_symlinks, n_ask_attempts) and returns: val