code: def expand_env_var(env_var: str) -> str:
      """Expands potentially nested env var by repeatedly applying `expandvars` and
      `expanduser` until interpolation stops having any effect.
      """
      while True:
          interpolated = os.path.expanduser(
              os.path.expandvars(str(env_var))
          )
          if interpolated == env_var:
              return interpolated
          else:
              env_var = interpolated
  
imports: from __future__ import annotations
  import importlib.metadata
  import logging
  import os
  import re
  import typing
  from functools import lru_cache
  from ...exceptions import BentoMLConfigException
  from ...exceptions import BentoMLException
label_desc: Use image node_id 1 for calling a global function with example usage: expand_env_var(env_var) and returns: interpolated