code: def collect_env(env: Mapping[str, str] | None = None) -> dict:
      """Collect config from environment variables
  
      This grabs environment variables of the form "DASK_FOO__BAR_BAZ=123" and
      turns these into config variables of the form ``{"foo": {"bar-baz": 123}}``
      It transforms the key and value in the following way:
  
      -  Lower-cases the key text
      -  Treats ``__`` (double-underscore) as nested access
      -  Calls ``ast.literal_eval`` on the value
  
      Any serialized config passed via ``DASK_INTERNAL_INHERIT_CONFIG`` is also set here.
  
      """
  
      if env is None:
          env = os.environ
  
      if "DASK_INTERNAL_INHERIT_CONFIG" in env:
          d = deserialize(env["DASK_INTERNAL_INHERIT_CONFIG"])
      else:
          d = {}
  
      for name, value in env.items():
          if name.startswith("DASK_"):
              varname = name[5:].lower().replace("__", ".")
              try:
                  d[varname] = ast.literal_eval(value)
              except (SyntaxError, ValueError):
                  if value.lower() in ("none", "null"):
                      d[varname] = None
                  else:
                      d[varname] = value
  
      result: dict = {}
      set(d, config=result)
      return result
  
imports: from __future__ import annotations
  import ast
  import base64
  import builtins
  import json
  import os
  import site
  import sys
  import threading
  import warnings
  from collections.abc import Mapping, Sequence
  from typing import Any, Literal
  import yaml
  from dask.typing import no_default
label_desc: Use image node_id 7 for calling a global function with example usage: collect_env(env) and returns: result