code: def from_conf(name, default=None, validate_fn=None):
      """
      First try to pull value from environment, then from metaflow config JSON
  
      Prior to a value being returned, we will validate using validate_fn (if provided).
      Only non-None values are validated.
  
      validate_fn should accept (name, value).
      If the value validates, return None, else raise an MetaflowException.
      """
      is_default = True
      env_name = "METAFLOW_%s" % name
      value = os.environ.get(
          env_name, METAFLOW_CONFIG.get(env_name, default)
      )
      if validate_fn and value is not None:
          validate_fn(env_name, value)
      if default is not None:
          # In this case, value is definitely not None because default is the ultimate
          # fallback and all other cases will return a string (even if an empty string)
          if isinstance(default, (list, dict)):
              # If we used the default, value is already a list or dict, else it is a
              # string so we can just compare types to determine is_default
              if isinstance(value, (list, dict)):
                  is_default = True
              else:
                  try:
                      value = json.loads(value)
                  except json.JSONDecodeError:
                      raise ValueError(
                          "Expected a valid JSON for %s, got: %s"
                          % (env_name, value)
                      )
                  if type(value) != type(default):
                      raise ValueError(
                          "Expected value of type '%s' for %s, got: %s"
                          % (type(default), env_name, value)
                      )
                  is_default = value == default
              _all_configs[env_name] = ConfigValue(
                  value=value,
                  serializer=json.dumps,
                  is_default=is_default,
              )
              return value
          elif isinstance(default, (bool, int, float)) or is_stringish(
              default
          ):
              try:
                  if type(value) != type(default):
                      if isinstance(default, bool):
                          # Env vars are strings so try to evaluate logically
                          value = value.lower() not in (
                              "0",
                              "false",
                              "",
                          )
                      else:
                          value = type(default)(value)
                  is_default = value == default
              except ValueError:
                  raise ValueError(
                      "Expected a %s for %s, got: %s"
                      % (type(default), env_name, value)
                  )
          else:
              raise RuntimeError(
                  "Default of type %s for %s is not supported"
                  % (type(default), env_name)
              )
      else:
          is_default = value is None
      _all_configs[env_name] = ConfigValue(
          value=value,
          serializer=str,
          is_default=is_default,
      )
      return value
  
file_path: metaflow/metaflow/metaflow_config_funcs.py
imports: import json
  import os
  from collections import namedtuple
  from metaflow.exception import MetaflowException
  from metaflow.util import is_stringish
label_desc: Use image node_id 3 for calling a global function with example usage: from_conf(name, default, validate_fn) and returns: value, value