ruturn the method for earliest package in ``pkg_preferences``, if package is available (based on :meth:`pkg_available`)
778684
def available_method(method_name):
    ''''''
    pkg_prefs_copy = list(pkg_prefs)
    if method_name in method_prefs:
        pkg_prefs_copy = [method_prefs[method_name]] + pkg_prefs_copy
    for pkg in pkg_prefs_copy:
        if pkg in pkgs:
            if method_name in dir(pkgs[pkg]):
                return getattr(pkgs[pkg],method_name)
    nl.notify('Error: Could not find implementation of %s on this computer' % (method_name),level=nl.level.error)
721934
private static String tryGetForbiddenPackageName(String classAndMethod) {

        for (String pkg : suppressedPackages) {
            if (classAndMethod.startsWith(pkg)) {
                return pkg;
            }
        }
        return null;
    }
626514
def diff_packages(pkg1, pkg2=None):
    
    if pkg2 is None:
        it = iter_packages(pkg1.name)
        pkgs = [x for x in it if x.version < pkg1.version]
        if not pkgs:
            raise RezError("No package to diff with - %s is the earliest "
                           "package version" % pkg1.qualified_name)
        pkgs = sorted(pkgs, key=lambda x: x.version)
        pkg2 = pkgs[-1]

    def _check_pkg(pkg):
        if not (pkg.vcs and pkg.revision):
            raise RezError("Cannot diff package %s: it is a legacy format "
                           "package that does not contain enough information"
                           % pkg.qualified_name)

    _check_pkg(pkg1)
    _check_pkg(pkg2)
    path = mkdtemp(prefix="rez-pkg-diff")
    paths = []

    for pkg in (pkg1, pkg2):
        print "Exporting %s..." % pkg.qualified_name
        path_ = os.path.join(path, pkg.qualified_name)
        vcs_cls_1 = plugin_manager.get_plugin_class("release_vcs", pkg1.vcs)
        vcs_cls_1.export(revision=pkg.revision, path=path_)
        paths.append(path_)

    difftool = config.difftool
    print "Opening diff viewer %s..." % difftool
    proc = Popen([difftool] + paths)
    proc.wait()
154628
def __priority(self, pr, repo, pkg):
        
        if (pr[0] == repo and pr[1].startswith("*") and
                pr[1].endswith("*")):
            if pr[1][1:-1] in pkg:
                self.black.append(self.__add(repo, pkg))
        elif pr[0] == repo and pr[1].endswith("*"):
            if pkg.startswith(pr[1][:-1]):
                self.black.append(self.__add(repo, pkg))
        elif pr[0] == repo and pr[1].startswith("*"):
            if pkg.endswith(pr[1][1:]):
                self.black.append(self.__add(repo, pkg))
        elif pr[0] == repo and "*" not in pr[1]:
            self.black.append(self.__add(repo, pkg))
571945
def checkInstalledPip(package, speak=True, speakSimilar=True):
    """"""
    packages = sorted([i.key for i in pip.get_installed_distributions()])
    installed = package in packages
    similar = None

    if not installed:
        similar = [pkg for pkg in packages if package in pkg]

    if speak:
        speakInstalledPackages(package, "pip", installed, similar, speakSimilar)

    return (installed, similar)
1301566
def _init_check_upodates():
    
    message, count, packages = check_updates()
    if count > 0:
        print(message)
        for pkg in packages:
            print("{0}".format(pkg))
    else:
        print(message)
910806
def find(self, package, **kwargs):
        
        spec = find_spec(package)
        if spec is None:
            return None
        limit = []
        if '.' in package:
            package, limit = package.split('.', 1)
            limit = [limit]
            spec = find_spec(package)
        if spec is not None:
            if spec.submodule_search_locations:
                path = spec.submodule_search_locations[0]
            elif spec.origin and spec.origin != 'built-in':
                path = spec.origin
            else:
                return None
            return PackageSpec(spec.name, path, limit)
        return None
25628
def default_hook(config):
    """"""
    if (any(arg.startswith('bdist') for arg in sys.argv) and
            os.path.isdir(PY2K_DIR) != IS_PY2K and os.path.isdir(LIB_DIR)):
        shutil.rmtree(LIB_DIR)

    if IS_PY2K and any(arg.startswith('install') or
                       arg.startswith('build') or
                       arg.startswith('bdist') for arg in sys.argv):
        generate_py2k(config)
        packages_root = get_cfg_value(config, 'files', 'packages_root')
        packages_root = os.path.join(PY2K_DIR, packages_root)
        set_cfg_value(config, 'files', 'packages_root', packages_root)
753989
def versions_available(self):
        

        if self.version:
            spec = "%s==%s" % (self.project_name, self.version)
        else:
            spec = self.project_name

        if self.all_versions and self.version in self.all_versions:
            print_pkg_versions(self.project_name, [self.version])
        elif not self.version and self.all_versions:
            print_pkg_versions(self.project_name, self.all_versions)
        else:
            if self.version:
                self.logger.error("No pacakge found for version %s" \
                        % self.version)
            else:
                self.logger.error("No pacakge found for %s" % self.project_name)
            return 1
        return 0
1029577
def package_version(package_name: str) -> typing.Optional[str]:
    

    try:
        return pkg_resources.get_distribution(package_name).version
    except (pkg_resources.DistributionNotFound, AttributeError):
        return None
873766
def getClassInPackageFromName(className, pkg):
    
    # TODO: more efficiency!
    n = getAvClassNamesInPackage(pkg)
    i = n.index(className)
    c = getAvailableClassesInPackage(pkg)
    return c[i]
276779
def _find_pkg_info(self):
        
        dist = pkg_resources.require(self.package_name)[0]
        self._pkg_resources_locations = [dist.location]
        ver, url = self._dist_version_url(dist)
        return {'version': ver, 'url': url}
1309599
def _discover_import(self, prefer=None):
        

        available_packages = self.packages
        if isinstance(prefer, str):
            available_packages = (prefer,)

        for module_name in available_packages:
            spec = importlib.util.find_spec(module_name)
            if spec is not None:
                importlib.import_module(module_name)
                imported_hook = getattr(self, f"on_{module_name}_imported", None)
                if callable(imported_hook):
                    imported_hook(sys.modules[module_name])
                return module_name
        raise ModuleNotFoundError(f"no modules in {available_packages!r} found")
405361
def was_installed_by_pip(pkg):
    # type: (str) -> bool
    
    try:
        dist = pkg_resources.get_distribution(pkg)
        return (dist.has_metadata('INSTALLER') and
                'pip' in dist.get_metadata_lines('INSTALLER'))
    except pkg_resources.DistributionNotFound:
        return False
144804
def finder(package):
    
    if package in _finder_cache:
        result = _finder_cache[package]
    else:
        if package not in sys.modules:
            __import__(package)
        module = sys.modules[package]
        path = getattr(module, '__path__', None)
        if path is None:
            raise DistlibException('You cannot get a finder for a module, '
                                   'only for a package')
        loader = getattr(module, '__loader__', None)
        finder_maker = _finder_registry.get(type(loader))
        if finder_maker is None:
            raise DistlibException('Unable to locate finder for %r' % package)
        result = finder_maker(module)
        _finder_cache[package] = result
    return result
855857
def common_package_action_options(f):
    """"""

    @click.option(
        "-s",
        "--skip-errors",
        default=False,
        is_flag=True,
        help="Skip/ignore errors when copying packages.",
    )
    @click.option(
        "-W",
        "--no-wait-for-sync",
        default=False,
        is_flag=True,
        help="Don't wait for package synchronisation to complete before " "exiting.",
    )
    @click.option(
        "-I",
        "--wait-interval",
        default=5.0,
        type=float,
        show_default=True,
        help="The time in seconds to wait between checking synchronisation.",
    )
    @click.option(
        "--sync-attempts",
        default=3,
        type=int,
        help="Number of times to attempt package synchronisation. If the "
        "package fails the first time, the client will attempt to "
        "automatically resynchronise it.",
    )
    @click.pass_context
    @functools.wraps(f)
    def wrapper(ctx, *args, **kwargs):
        # pylint: disable=missing-docstring
        return ctx.invoke(f, *args, **kwargs)

    return wrapper
522750
function findSatisfying (pkg, name, range, mustHave, reg) {
  if (mustHave) return null
  return semver.maxSatisfying
         ( Object.keys(reg[name] || {})
           .concat(Object.keys(Object.getPrototypeOf(reg[name] || {})))
         , range
         )
}