code: def _convert_env(
      env: str | list[str] | dict[str, str] | None
  ) -> dict[str, str] | dict[str, str | None] | None:
      if env is None:
          return None
  
      if isinstance(env, str):
          env_path = os.path.expanduser(os.path.expandvars(env))
          if os.path.exists(env_path):
              logger.debug(
                  "Reading dot env file '%s' specified in config", env
              )
              with open(env_path) as f:
                  return parse_dotenv(f.read())
          raise BentoMLException(
              f"'{env}' is not a valid '.env' file path"
          )
  
      if isinstance(env, list):
          env_dict: dict[str, str | None] = {}
          for envvar in env:
              if not re.match(r"^(\w+)=(?:[\.\w\-,\/]+)$", envvar):
                  raise BentoMLException(
                      "All value in `env` list must follow format ENV=VALUE"
                  )
              env_key, _, env_value = envvar.partition("=")
              if os.path.isfile(env_value):
                  bento_env_path = BENTO_PATH + os.path.abspath(
                      os.path.expanduser(os.path.expandvars(env_value))
                  )
                  logger.info(
                      "'%s' sets to '%s', which is a file. Make sure to mount this file as a persistent volume to the container when using 'run' command: 'docker run -v %s:%s ...'",
                      env_key,
                      env_value,
                      env_value,
                      bento_env_path,
                  )
                  env_value = bento_env_path
              env_dict[env_key] = env_value
          return env_dict
  
      if isinstance(env, dict):
          # convert all dict key and values to string
          return {str(k): str(v) for k, v in env.items()}
  
      raise BentoMLException(
          f"`env` must be either a list, a dict, or a path to a dot environment file, got type '{type(env)}' instead."
      )
  
imports: from __future__ import annotations
  import logging
  import os
  import re
  import subprocess
  import sys
  import typing
  from shlex import quote
  from sys import version_info
  import attr
  import fs
  import fs.copy
  import psutil
  import yaml
  from pathspec import PathSpec
  from ...exceptions import BentoMLException
  from ...exceptions import InvalidArgument
  from ..configuration import BENTOML_VERSION
  from ..configuration import clean_bentoml_version
  from ..configuration import get_quiet_mode
  from ..container import generate_containerfile
  from ..container.frontend.dockerfile import ALLOWED_CUDA_VERSION_ARGS
  from ..container.frontend.dockerfile import CONTAINER_SUPPORTED_DISTROS
  from ..container.frontend.dockerfile import SUPPORTED_CUDA_VERSIONS
  from ..container.frontend.dockerfile import DistroSpec
  from ..container.frontend.dockerfile import get_supported_spec
  from ..container.generate import BENTO_PATH
  from ..utils import bentoml_cattr
  from ..utils import copy_file_to_fs_folder
  from ..utils import resolve_user_filepath
  from ..utils.dotenv import parse_dotenv
  from .build_dev_bentoml_whl import build_bentoml_editable_wheel
label_desc: Use image node_id 3 for calling a global function with example usage: _convert_env(env) and returns: None, env_dict, unknown, parse_dotenv