docs: def prepare_env(gdef='', gvars={}, extra_vars={}, host='localhost'):
      '''clear current sos_dict, execute global_def (definitions and imports),
      and inject global variables'''
      env.sos_dict.clear()
  
      if not gdef and not gvars:
          # SoS Notebook calls prepare_env without global statement from a
          # particular
          gdef, gvars = analyze_global_statements('')
  
      if gdef:
          exec(compile(gdef, filename="<ast>", mode="exec"), env.sos_dict._dict)
  
      env.sos_dict.quick_update(gvars)
      env.sos_dict.quick_update(extra_vars)
      if 'CONFIG' not in env.sos_dict:
          # if this is in sos notebook
          load_config_files()
      if 'hosts' not in env.sos_dict[
              'CONFIG'] and 'localhost' not in env.sos_dict['CONFIG']:
          env.sos_dict['CONFIG']['localhost'] = 'localhost'
          env.sos_dict['CONFIG']['hosts'] = {
              'localhost': {
                  'paths': {},
                  'address': 'localhost'
              }
          }
      # expose `paths` of localhost
      if host == 'localhost':
          if 'localhost' in env.sos_dict['CONFIG']:
              if 'hosts' not in env.sos_dict['CONFIG'] or env.sos_dict['CONFIG'][
                      'localhost'] not in env.sos_dict['CONFIG']['hosts']:
                  env.logger.warning(
                      f"Localhost {env.sos_dict['CONFIG']['localhost']} is not defined in CONFIG['hosts']"
                  )
                  env.sos_dict['CONFIG']['hosts'][env.sos_dict['CONFIG']
                                                  ['localhost']] = {
                                                      'paths': {},
                                                      'address': 'localhost'
                                                  }
              env.sos_dict.set('__host__', env.sos_dict['CONFIG']['localhost'])
          else:
              if 'hosts' in env.sos_dict['CONFIG']:
                  if 'localhost' not in env.sos_dict['CONFIG']['hosts']:
                      env.logger.warning('locahost is not defined in "hosts".')
                      env.sos_dict['CONFIG']['hosts']['localhost'] = {
                          'paths': {},
                          'address': 'localhost'
                      }
              elif 'paths' not in env.sos_dict['CONFIG']['hosts']['localhost']:
                  env.sos_dict['CONFIG']['hosts']['localhost']['paths'] = {}
              env.sos_dict.set('__host__', 'localhost')
      else:
          if 'hosts' not in env.sos_dict['CONFIG'] or host not in env.sos_dict[
                  'CONFIG']['hosts']:
              raise RuntimeError(
                  f"Remote host {host} is not defined in CONFIG['hosts']. Available ones are {env.sos_dict['CONFIG']['hosts'].keys()}"
              )
          env.sos_dict.set('__host__', host)