Loader that loads any eggs in `sys.path`.
429951
def load_eggs(entry_point_name):
    """"""

    def _load_eggs():
        distributions, errors = working_set.find_plugins(Environment())
        for dist in distributions:
            # pylint: disable=unsupported-membership-test
            if dist not in working_set:
                LOGGER.debug('Adding plugin %s from %s', dist, dist.location)
                working_set.add(dist)

        def _log_error(item, err):
            if isinstance(err, DistributionNotFound):
                LOGGER.debug('Skipping "%s": ("%s" not found)', item, err)
            elif isinstance(err, VersionConflict):
                LOGGER.error('Skipping "%s": (version conflict "%s")', item, err)
            elif isinstance(err, UnknownExtra):
                LOGGER.error('Skipping "%s": (unknown extra "%s")', item, err)
            else:
                LOGGER.error('Skipping "%s": %s', item, err)

        for dist, err in errors.items():
            _log_error(dist, err)

        for entry in sorted(
            working_set.iter_entry_points(entry_point_name),
            key=lambda entry: entry.name,
        ):
            try:
                entry.load(require=True)
            except Exception as exc:  # pylint: disable=broad-except
                _log_error(entry, exc)

    return _load_eggs
261676
def load_module(self, path, changed_time, parser=None):
        """"""
        if settings.use_filesystem_cache == False:
            return None
        
        try:
            pickle_changed_time = self._index[path]
        except KeyError:
            return None

        if (changed_time is not None and
            pickle_changed_time < changed_time):
            # the pickle file is outdated
            return None

        target_path = self._get_hashed_path(path)
        with open(target_path, 'rb') as f:
            try:
                gc.disable()
                cache_module = pickle.load(f)
                if parser is not None:
                    for mod in cache_module:
                        mod.unpickle(parser)
            finally:
                gc.enable()

        debug.dbg('pickle loaded: %s', path)
        return cache_module
990864
def load_object(path):
    """"""
    i = path.rfind('.')
    module_name, object_name = path[:i], path[i + 1:]
    # Load module.
    try:
        module = import_module(module_name)
    except ImportError:
        raise ImproperlyConfigured('Module %r not found' % module_name)
    except ValueError:
        raise ImproperlyConfigured('Invalid module %r' % module_name)
    # Load object.
    try:
        return getattr(module, object_name)
    except AttributeError:
        msg = 'Module %r does not define an object named %r'
        raise ImproperlyConfigured(msg % (module_name, object_name))
958710
def load_apis(self, path, ignore=[], include_crash_api=False):
        """"""

        if not path:
            raise Exception("Missing path to api swagger files")

        if type(ignore) is not list:
            raise Exception("'ignore' should be a list of api names")

        # Always ignore pym-config.yaml
        ignore.append('pym-config')

        # Find all swagger apis under 'path'
        apis = {}

        log.debug("Searching path %s" % path)
        for root, dirs, files in os.walk(path):
            for f in files:
                if f.endswith('.yaml'):
                    api_name = f.replace('.yaml', '')

                    if api_name in ignore:
                        log.info("Ignoring api %s" % api_name)
                        continue

                    apis[api_name] = os.path.join(path, f)
                    log.debug("Found api %s in %s" % (api_name, f))

        # And add pymacaron's default ping and crash apis
        for name in ['ping', 'crash']:
            yaml_path = pkg_resources.resource_filename(__name__, 'pymacaron/%s.yaml' % name)
            if not os.path.isfile(yaml_path):
                yaml_path = os.path.join(os.path.dirname(sys.modules[__name__].__file__), '%s.yaml' % name)
            apis[name] = yaml_path

        if not include_crash_api:
            del apis['crash']

        # Save found apis
        self.path_apis = path
        self.apis = apis

        return self
857794
def load_collectors_from_paths(paths):
    
    # Initialize return value
    collectors = {}

    if paths is None:
        return

    if isinstance(paths, basestring):
        paths = paths.split(',')
        paths = map(str.strip, paths)

    load_include_path(paths)

    for path in paths:
        # Get a list of files in the directory, if the directory exists
        if not os.path.exists(path):
            raise OSError("Directory does not exist: %s" % path)

        if path.endswith('tests') or path.endswith('fixtures'):
            return collectors

        # Load all the files in path
        for f in os.listdir(path):

            # Are we a directory? If so process down the tree
            fpath = os.path.join(path, f)
            if os.path.isdir(fpath):
                subcollectors = load_collectors_from_paths([fpath])
                for key in subcollectors:
                    collectors[key] = subcollectors[key]

            # Ignore anything that isn't a .py file
            elif (os.path.isfile(fpath) and
                  len(f) > 3 and
                  f[-3:] == '.py' and
                  f[0:4] != 'test' and
                  f[0] != '.'):

                modname = f[:-3]

                fp, pathname, description = imp.find_module(modname, [path])

                try:
                    # Import the module
                    mod = imp.load_module(modname, fp, pathname, description)
                except (KeyboardInterrupt, SystemExit) as err:
                    logger.error(
                        "System or keyboard interrupt "
                        "while loading module %s"
                        % modname)
                    if isinstance(err, SystemExit):
                        sys.exit(err.code)
                    raise KeyboardInterrupt
                except Exception:
                    # Log error
                    logger.error("Failed to import module: %s. %s",
                                 modname,
                                 traceback.format_exc())
                else:
                    for name, cls in get_collectors_from_module(mod):
                        collectors[name] = cls
                finally:
                    if fp:
                        fp.close()

    # Return Collector classes
    return collectors
1186499
def _load(self):
        """'"""
        # loop over system path
        if self._loaded:
            return
        icon_paths = ['/usr/local/share/meqtrees'] + sys.path
        for path in icon_paths:
            path = path or '.'
            # for each entry, try <entry>/icons/<appname>'
            for a, b in [('icons', self._appname), (self._appname, 'icons')]:
                trydir = os.path.join(path, a, b)
                _dprint(3, 'trying icon path', trydir)
                try:
                    files = os.listdir(trydir)
                except:
                    continue
                _dprint(3, len(files), 'entries in', trydir)
                # loop over all files
                nicons = 0
                for f in files:
                    (name, ext) = os.path.splitext(f);  # check extension
                    if ext in ('.png', '.xpm', '.gif'):
                        f = os.path.join(trydir, f)
                        try:
                            pm = QPixmap(f)
                        except:
                            _dprint(3, 'error loading icon', name, sys.exc_value())
                            continue
                        # register pixmap
                        self._pixmaps[name] = QPixmapWrapper(pm)
                        nicons += 1
                        _dprint(4, 'loaded icon', f)
                    else:
                        _dprint(4, 'ignoring entry', f)
                _dprint(1, nicons, 'icons loaded from ', trydir)
                self._loaded = True
885954
def temp_path():
    """"""
    path = [p for p in sys.path]
    try:
        yield
    finally:
        sys.path = [p for p in path]
1362237
def pickle_load(fname):
    """"""
    assert type(fname) is str and os.path.exists(fname)
    print("loaded",fname)
    return pickle.load(open(fname,"rb"))
868885
def load(self, patterns, dirs, ignore=None):
        
        for path in self.find_files(patterns=patterns, dirs=dirs, ignore=ignore):
            data = self.read_file(path=path)
            if data:
                self.paths[path] = data
141138
def load_config(cls, opts, path=None, profile=None):
        """"""
        if path and os.path.exists(path):
            if os.path.isdir(path):
                cls.config_searchpath.insert(0, path)
            else:
                cls.config_files.insert(0, path)

        config = cls.read_config()
        values = config.get("default", {})
        cls._load_values_into_opts(opts, values)

        if profile and profile != "default":
            values = config.get("profile:%s" % profile, {})
            cls._load_values_into_opts(opts, values)

        return values
1308981
def export_live_eggs(self, env=False):
        """"""
        path_eggs = [p for p in sys.path if p.endswith('.egg')]

        command = self.get_finalized_command("egg_info")
        egg_base = path.abspath(command.egg_base)

        unique_path_eggs = set(path_eggs + [egg_base])

        os.environ['PYTHONPATH'] = ':'.join(unique_path_eggs)
1217597
def egg2dist(self, egginfo_path, distinfo_path):
        """"""
        def adios(p):
            """Appropriately delete directory, file or link."""
            if os.path.exists(p) and not os.path.islink(p) and os.path.isdir(p):
                shutil.rmtree(p)
            elif os.path.exists(p):
                os.unlink(p)

        adios(distinfo_path)

        if not os.path.exists(egginfo_path):
            # There is no egg-info. This is probably because the egg-info
            # file/directory is not named matching the distribution name used
            # to name the archive file. Check for this case and report
            # accordingly.
            import glob
            pat = os.path.join(os.path.dirname(egginfo_path), '*.egg-info')
            possible = glob.glob(pat)
            err = "Egg metadata expected at %s but not found" % (egginfo_path,)
            if possible:
                alt = os.path.basename(possible[0])
                err += " (%s found - possible misnamed archive file?)" % (alt,)

            raise ValueError(err)

        if os.path.isfile(egginfo_path):
            # .egg-info is a single file
            pkginfo_path = egginfo_path
            pkg_info = pkginfo_to_metadata(egginfo_path, egginfo_path)
            os.mkdir(distinfo_path)
        else:
            # .egg-info is a directory
            pkginfo_path = os.path.join(egginfo_path, 'PKG-INFO')
            pkg_info = pkginfo_to_metadata(egginfo_path, pkginfo_path)

            # ignore common egg metadata that is useless to wheel
            shutil.copytree(egginfo_path, distinfo_path,
                            ignore=lambda x, y: {'PKG-INFO', 'requires.txt', 'SOURCES.txt',
                                                 'not-zip-safe'}
                            )

            # delete dependency_links if it is only whitespace
            dependency_links_path = os.path.join(distinfo_path, 'dependency_links.txt')
            with open(dependency_links_path, 'r') as dependency_links_file:
                dependency_links = dependency_links_file.read().strip()
            if not dependency_links:
                adios(dependency_links_path)

        write_pkg_info(os.path.join(distinfo_path, 'METADATA'), pkg_info)

        # XXX heuristically copy any LICENSE/LICENSE.txt?
        license = self.license_file()
        if license:
            license_filename = 'LICENSE.txt'
            shutil.copy(license, os.path.join(distinfo_path, license_filename))

        adios(egginfo_path)
1164744
def load_code(self, path, package, callwith):
        '''
        
        '''
        sys.path = [path] + sys.path
        g_o = importlib.import_module(package).get_objects
        del sys.path[0]
        for obj in g_o(callwith):
            self.code[obj.title.lower()] = obj
864562
def load_all(stream, Loader=Loader):
    
    loader = Loader(stream)
    try:
        while loader.check_data():
            yield loader.get_data()
    finally:
        loader.dispose()
617667
def get_script_from_egg(name, dist):
  """"""
  if dist.metadata_isdir('scripts') and name in dist.metadata_listdir('scripts'):
    return (
        os.path.join(dist.egg_info, 'scripts', name),
        dist.get_metadata('scripts/%s' % name).replace('\r\n', '\n').replace('\r', '\n'))
  return None, None
678718
def load(config):
    

    if config.sys_path:
        logger.debug("Appending %s to sys.path.", config.sys_path)
        sys.path.append(config.sys_path)
        logger.debug("sys.path is now %s", sys.path)
    if config.lookups:
        for key, handler in config.lookups.items():
            register_lookup_handler(key, handler)

    return config
981785
def _load_start_paths(self):
        "  "
        if self._startup_paths:
            for path in self._startup_paths:
                if os.path.exists(path):
                    with open(path, 'rb') as f:
                        code = compile(f.read(), path, 'exec')
                        six.exec_(code, self.get_globals(), self.get_locals())
                else:
                    output = self.app.output
                    output.write('WARNING | File not found: {}\n\n'.format(path))