def install(h, pip, groups, save, save_dev, packages):
    """Install a pip or bower package."""
    if groups:
        groups = [text_type.strip(group) for group in groups.split(",")]
    else:
        groups = h.requirements.keys()

    if not packages:
        for group in groups:
            if group not in h.requirements:
                warning("{} not in requirements".format(group))
                continue
            install = (h.install_bower if group.startswith("bower")
                       else h.install_pip)
            for requirement in h.requirements[group]:
                install(str(requirement), save=False, save_dev=False)
    if pip:
        for package in packages:
            h.install_pip(package, save=save, save_dev=save_dev)
    else:
        for package in packages:
            h.install_bower(package, save=save, save_dev=save_dev)
def _donormalize(patterns, default, root, cwd, auditor, warn):
    """Convert 'kind:pat' from the patterns list to tuples with kind and
    normalized and rooted patterns and with listfiles expanded."""
    kindpats = []
    for kind, pat in [_patsplit(p, default) for p in patterns]:
        if kind in cwdrelativepatternkinds:
            pat = pathutil.canonpath(root, cwd, pat, auditor)
        elif kind in ("relglob", "path", "rootfilesin"):
            pat = util.normpath(pat)
        elif kind in ("listfile", "listfile0"):
            try:
                files = decodeutf8(util.readfile(pat))
                if kind == "listfile0":
                    files = files.split("\0")
                else:
                    files = files.splitlines()
                files = [f for f in files if f]
            except EnvironmentError:
                raise error.Abort(_("unable to read file list (%s)") % pat)
            for k, p, source in _donormalize(files, default, root, cwd, auditor, warn):
                kindpats.append((k, p, pat))
            continue
        elif kind == "include":
            try:
                fullpath = os.path.join(root, util.localpath(pat))
                includepats = readpatternfile(fullpath, warn)
                for k, p, source in _donormalize(
                    includepats, default, root, cwd, auditor, warn
                ):
                    kindpats.append((k, p, source or pat))
            except error.Abort as inst:
                raise error.Abort("%s: %s" % (pat, inst[0]))
            except IOError as inst:
                if warn:
                    warn(
                        _("skipping unreadable pattern file '%s': %s\n")
                        % (pat, inst.strerror)
                    )
            continue
        # else: re or relre - which cannot be normalized
        kindpats.append((kind, pat, ""))
    return kindpats