'Create the buffer-independent list of libs.'

def _buf_indep_libs_from_env(self, env):

    cache_key = (self.lang + '-libs')
    libs = env.cache.get(cache_key)
    if (libs is None):
        env.add_pref_observer(self.interpreterPrefName, self._invalidate_cache)
        env.add_pref_observer(self.extraPathsPrefName, self._invalidate_cache_and_rescan_extra_dirs)
        env.add_pref_observer('codeintel_selected_catalogs', self._invalidate_cache)
        db = self.mgr.db
        (ver, prefix, libdir, sitelibdir, sys_path) = self.python_info_from_env(env)
        libs = []
        extra_dirs = self._extra_dirs_from_env(env)
        if extra_dirs:
            libs.append(db.get_lang_lib(self.lang, 'extradirslib', extra_dirs))
        paths_from_libname = {'sitelib': [], 'envlib': [], 'stdlib': []}
        canon_sitelibdir = ((sitelibdir and normcase(sitelibdir)) or None)
        canon_prefix = ((prefix and normcase(prefix)) or None)
        canon_libdir = ((libdir and normcase(libdir)) or None)
        canon_libdir_plat_prefix = ((libdir and normcase(join(libdir, 'plat-'))) or None)
        canon_libdir_lib_prefix = ((libdir and normcase(join(libdir, 'lib-'))) or None)
        for dir in sys_path:
            STATE = 'envlib'
            canon_dir = normcase(dir)
            if (dir == ''):
                continue
            elif (canon_dir.endswith('.zip') and isfile(dir)):
                log.warn("`%s':    not    handling    .zip    file    on    Python    sys.path", dir)
                continue
            elif (canon_dir.endswith('.egg') and isfile(dir)):
                continue
            elif canon_dir.startswith(canon_sitelibdir):
                STATE = 'sitelib'
            elif ((canon_dir == canon_libdir) or canon_dir.startswith(canon_libdir_plat_prefix) or canon_dir.startswith(canon_libdir_lib_prefix)):
                STATE = 'stdlib'
            if (not exists(dir)):
                continue
            paths_from_libname[STATE].append(dir)
        log.debug('Python    %s    paths    for    each    lib:\n%s', ver, indent(pformat(paths_from_libname)))
        if paths_from_libname['envlib']:
            libs.append(db.get_lang_lib(self.lang, 'envlib', paths_from_libname['envlib']))
        if paths_from_libname['sitelib']:
            libs.append(db.get_lang_lib(self.lang, 'sitelib', paths_from_libname['sitelib']))
        catalog_selections = env.get_pref('codeintel_selected_catalogs')
        libs += [db.get_catalog_lib(self.lang, catalog_selections), db.get_stdlib(self.lang, ver)]
        env.cache[cache_key] = libs
    return libs
