def _install_pkg_version(env, pkg, args, version, brew_cmd, ipkgs):
    if ipkgs["current"].get(pkg.split("/")[-1]) == version:
        return
    if version == "HEAD":
        args = " ".join(args)
        brew_install = _get_brew_install_cmd(brew_cmd, env, pkg)
        env.safe_run("{brew_install} {args} --HEAD {pkg}".format(**locals()))
    else:
        raise ValueError("Cannot currently handle installing brew packages by version.")
        with _git_pkg_version(env, brew_cmd, pkg, version):
            if pkg.split("/")[-1] in ipkgs["current"]:
                with settings(warn_only=True):
                    env.safe_run("{brew_cmd} unlink {pkg}".format(
                        brew_cmd=brew_cmd, pkg=pkg.split("/")[-1]))
            # if we have a more recent version, uninstall that first
            cur_version_parts = env.safe_run_output("{brew_cmd} list --versions {pkg}".format(
                brew_cmd=brew_cmd, pkg=pkg.split("/")[-1])).strip().split()
            if len(cur_version_parts) > 1 and LooseVersion(cur_version_parts[1]) > LooseVersion(version):
                with settings(warn_only=True):
                    env.safe_run("{brew_cmd} uninstall {pkg}".format(**locals()))
            env.safe_run("{brew_cmd} install {pkg}".format(**locals()))
            with settings(warn_only=True):
                env.safe_run("{brew_cmd} switch {pkg} {version}".format(**locals()))
    env.safe_run("%s link --overwrite %s" % (brew_cmd, pkg))
Install a specific version of a package by retrieving from git history.
dataset/ETHPy150Open chapmanb/cloudbiolinux/cloudbio/package/brew.py/_install_pkg_version