Finds packages install prefix (or None) and it's containing Folder
163026
def find_package(name: str) -> Tuple[Optional[Path], Path]:
    
    module = name.split(".")[0]
    loader = pkgutil.get_loader(module)
    if name == "__main__" or loader is None:
        package_path = Path.cwd()
    else:
        if hasattr(loader, 'get_filename'):
            filename = loader.get_filename(module)  # type: ignore
        else:
            __import__(name)
            filename = sys.modules[name].__file__
        package_path = Path(filename).resolve().parent
        if hasattr(loader, 'is_package'):
            is_package = loader.is_package(module)  # type: ignore
            if is_package:
                package_path = Path(package_path).resolve().parent
    sys_prefix = Path(sys.prefix).resolve()
    try:
        package_path.relative_to(sys_prefix)
    except ValueError:
        return None, package_path
    else:
        return sys_prefix, package_path
953449
def find_release(package, releases, dependencies=None):
    """"""
    dependencies = dependencies if dependencies is not None else {}
    for release in releases:
        url = release['url']
        old_priority = dependencies.get(package, {}).get('priority', 0)

        for suffix, priority in SUFFIXES.items():
            if url.endswith(suffix):
                if old_priority < priority:
                    sha256 = release['digests']['sha256']
                    dependencies[package] = {
                        'package': package,
                        'url': url,
                        'sha256': sha256,
                        'priority': priority,
                    }

    return dependencies[package]
1092572
def find_lib_dir(root):
    """"""
    root = path(root)
    log.debug('files in dir: %s', root)
    for x in root.walkfiles():
        log.debug('  %s', x)

    # only 1 dir in root? (example: github)
    if not len(root.files()) and len(root.dirs()) == 1:
        log.debug('go inside root')
        root = root.dirs()[0]

    if len(root.files('keywords.txt')):
        root = rename_root(root)
        return root, root

    keywords = list(root.walkfiles('keywords.txt'))
    if len(keywords):
        if len(keywords) > 1:
            log.warning('more keywords.txt found. Installing only one.  %s', keywords)  

        lib_dir = keywords[0].parent
        lib_dir = fix_libdir(lib_dir)
        return root, lib_dir

    header_only = len(list(noexample(root.walkfiles('*.cpp')))) == 0
    log.debug('header_only: %s', header_only)
    lib_dir = None

    headers = list(noexample(root.walkfiles('*.h')))

    for h in headers:
        cpp = h.stripext() + '.cpp'
        if (header_only or cpp.exists()) and h.parent.name.lower() == h.namebase.lower():
            assert not lib_dir
            lib_dir = h.parent
            log.debug('found lib: %s', lib_dir)

    if not lib_dir:
        if len(headers) == 1 and len(list(root.files('*.h'))) == 0:
            log.debug('only 1 header, not in root')
            lib_dir = headers[0].parent
            lib_dir = rename_root(lib_dir)

    if not lib_dir:
        # xxx.cpp and xxx.h in root? -> rename root dir
        root = rename_root(root)
        return root, root
#        for h in root.files('*.h'):
#            cpp = h.stripext() + '.cpp'
#            if  header_only or cpp.exists():
#                assert not lib_dir
#                root.rename(root.parent / h.namebase)
#                root = lib_dir = root.parent / h.namebase
    assert lib_dir
    return root, lib_dir
102212
def get_none_packages(self):
        
        not_found = set()
        for package_name, package in self.packages.items():
            if package is None:
                not_found.add(package_name)
            else:
                if package.packages:
                    not_found = not_found | package.get_none_packages()
        return not_found
881785
def get_installed_distributions(skip=stdlib_pkgs):
    
    return [d for d in pkg_resources.working_set
            if d.key not in skip]
218445
def filter_installed_packages(packages):
    """"""
    cache = apt_cache()
    _pkgs = []
    for package in packages:
        try:
            p = cache[package]
            p.current_ver or _pkgs.append(package)
        except KeyError:
            log('Package {} has no installation candidate.'.format(package),
                level='WARNING')
            _pkgs.append(package)
    return _pkgs
925650
def filter_installed_packages(packages):
    """"""
    yb = yum.YumBase()
    package_list = yb.doPackageLists()
    temp_cache = {p.base_package_name: 1 for p in package_list['installed']}

    _pkgs = [p for p in packages if not temp_cache.get(p, False)]
    return _pkgs
1095510
function findPackages(path) {
  return new Promise(function (resolve, reject) {
    (0, _glob.glob)(path, function (err, res) {
      if (err) {
        reject(err);
      }
      resolve(res.filter(function (file) {
        return file.endsWith('.json');
      }));
    });
  });
}
970876
function findPackage(filename) {
    if (!ctr)
        return;
    filename = filename || require.main.filename;
    var parsed = path_1.parse(filename);
    var curPath = path_1.join(parsed.dir, 'package.json');
    if (!fs_1.existsSync(curPath)) {
        ctr--;
        return findPackage(parsed.dir);
    }
    else {
        return chek_1.tryRequire(curPath, {});
    }
}
104344
def find_packages(recursive=True, maxdepth=None):
    
    import utool
    if utool.VERBOSE:
        print('[util_setup] find_packages(recursive=%r, maxdepth=%r)' % (recursive, maxdepth))
    from os.path import relpath
    cwd = os.getcwd()
    init_files = utool.glob(cwd, '__init__.py', recursive=recursive, maxdepth=maxdepth)
    package_paths = list(map(dirname, init_files))
    package_relpaths = [relpath(path, cwd) for path in package_paths]

    packages = []
    for path in package_relpaths:
        base = utool.dirsplit(path)[0]
        if exists(join(base, '__init__.py')):
            package = path.replace('/', '.').replace('\\', '.')
            packages.append(package)
    return packages
302748
function findPackage(config, match) {
  var map = getPackageMap(config.relativeTo, config.packages);

  return _.reduce(map, function (prev, pkg) {

    // Resolve using last priority. Priority:
    // 1. package is a file
    // 2. package granularity (done by file depth)
    if (pkg.regexp.test(match) && (!prev || (pkg.dir && prev.dir && pkg.depth >= pkg.depth) || pkg.file)) {
      return pkg;
    } else {
      return prev;
    }

  }, null);
}
850533
def _directory_prefix(self):
        
        if self.downder == "wget":
            self.dir_prefix = "--directory-prefix="
        elif self.downder == "aria2c":
            self.dir_prefix = "--dir="
728996
def get_prefix(dir="../"):
    
    prefix = glob(dir + "*.gkpStore")[0]
    prefix = op.basename(prefix).rsplit(".", 1)[0]

    return prefix
96911
def find_package(cls, team, user, package, pkghash=None, store_dir=None):
        
        cls.check_name(team, user, package)
        dirs = cls.find_store_dirs()
        for store_dir in dirs:
            store = PackageStore(store_dir)
            pkg = store.get_package(team, user, package, pkghash=pkghash)
            if pkg is not None:
                return store, pkg
        return None, None
77548
function findPackages(packagesPath) {
  return fs.readdirSync(packagesPath).reduce((acc, d) => {
    const fullpath = path.resolve(packagesPath, d);

    if (fs.statSync(fullpath).isDirectory()) {
      try {
        fs.statSync(path.resolve(fullpath, 'package.json'));
        acc.push(fullpath);
      }
      catch (err) {
        if (err.code === 'ENOENT') {
          return acc.concat(findPackages(fullpath));
        }
        throw err;
      }
    }

    return acc;
  }, []);
}
976
def _build_package_finder(self, options, index_urls):
        
        return PackageFinder(find_links=options.find_links,
                             index_urls=index_urls,
                             use_mirrors=options.use_mirrors,
                             mirrors=options.mirrors)
721903
def find_packages(name, pkg_dir):
    """"""
    for c in (FileSystemPackageBuilder, ZipPackageBuilder, ExcelPackageBuilder):

        package_path, cache_path = c.make_package_path(pkg_dir, name)

        if package_path.exists():

            yield c.type_code, package_path, cache_path