code: def set_config(key, value, home_dir=None, set_env=True):
      """Set a MNE-Python preference key in the config file and environment.
  
      Parameters
      ----------
      key : str
          The preference key to set.
      value : str |  None
          The value to assign to the preference key. If None, the key is
          deleted.
      home_dir : str | None
          The folder that contains the .mne config folder.
          If None, it is found automatically.
      set_env : bool
          If True (default), update :data:`os.environ` in addition to
          updating the MNE-Python config file.
  
      See Also
      --------
      get_config
      """
      _validate_type(key, "str", "key")
      # While JSON allow non-string types, we allow users to override config
      # settings using env, which are strings, so we enforce that here
      _validate_type(value, (str, "path-like", type(None)), "value")
      if value is not None:
          value = str(value)
  
      if key not in _known_config_types and not any(
          key.startswith(k) for k in _known_config_wildcards
      ):
          warn('Setting non-standard config type: "%s"' % key)
  
      # Read all previous values
      config_path = get_config_path(home_dir=home_dir)
      if op.isfile(config_path):
          config = _load_config(config_path, raise_error=True)
      else:
          config = dict()
          logger.info(
              "Attempting to create new mne-python configuration "
              "file:\n%s" % config_path
          )
      if value is None:
          config.pop(key, None)
          if set_env and key in os.environ:
              del os.environ[key]
      else:
          config[key] = value
          if set_env:
              os.environ[key] = value
          if key == "MNE_BROWSER_BACKEND":
              from ..viz._figure import set_browser_backend
  
              set_browser_backend(value)
  
      # Write all values. This may fail if the default directory is not
      # writeable.
      directory = op.dirname(config_path)
      if not op.isdir(directory):
          os.mkdir(directory)
      with open(config_path, "w") as fid:
          json.dump(config, fid, sort_keys=True, indent=0)
  
imports: import atexit
  import json
  import multiprocessing
  import os
  import os.path
  import platform
  import shutil
  import subprocess
  import sys
  import tempfile
  from functools import lru_cache, partial
  from importlib import import_module
  from pathlib import Path
  from urllib.error import URLError
  from urllib.request import urlopen
  from packaging.version import parse
  from ._logging import logger, warn
  from .check import _check_fname, _check_option, _check_qt_version, _validate_type
  from .docs import fill_doc
  from .misc import _pl
label_desc: Use image node_id 6 for calling a global function with example usage: set_config(key, value, home_dir, set_env) without return types