def get_bower_package(self, url, dest=None, version=None,
                          process_deps=True):
        dest = dest or Path(".") / "assets"
        parsed_url = urlparse(url)
        if parsed_url.scheme == "git" or parsed_url.path.endswith(".git"):
            if parsed_url.netloc == "github.com":
                user, repo = parsed_url.path[1:-4].split("/")
                response = get(github_api_uri +
                               "/repos/{}/{}/tags".format(user, repo))
                tags = response.json()
                target = None
                if not len(tags):
                    click.secho("fatal: no tags exist for {}/{}".format(
                        user, repo), fg="red")
                    raise InvalidPackageError
                if version is None:
                    target = tags[0]
                else:
                    for tag in tags:
                        if semver.match(tag["name"],
                                        Bower.clean_semver(version)):
                            target = tag
                            break
                if not target:
                    click.secho(
                        "fatal: failed to find matching tag for "
                        "{user}/{repo} {version}".format(user, repo, version),
                        fg="red")
                    raise VersionNotFoundError
                click.secho("installing {}/{}#{}".format(
                    user, repo, tags[0]["name"]), fg="green")
                return self.get_bower_package(
                    url=target["zipball_url"],
                    dest=dest,
                    version=version)
            raise NotImplementedError
            click.echo("git clone {url}".format(url=url))
            cmd = envoy.run('git clone {url} "{dest}"'.format(
                url=url, dest=dest))
        elif parsed_url.scheme in ("http", "https"):
            zip_dest = download_file(url, dest=self.temp_dir,
                                     label="{dest_basename}",
                                     expected_extension="zip")
            with zipfile.ZipFile(zip_dest, "r") as pkg:
                return self.extract_bower_zipfile(pkg, dest,
                                                  expected_version=version)
                # pkg.extractall(str(dest))
        else:
            click.secho("protocol currently unsupported :(")
            sys.exit(1)
def _buildvisitdir(kindpats):
    """Try to build an efficient visitdir function

    Return a visitdir function if it's built. Otherwise return None
    if there are unsupported patterns.

    >>> _buildvisitdir([('include', 'foo', '')])
    >>> _buildvisitdir([('relglob', 'foo', '')])
    >>> t = _buildvisitdir([
    ...     ('glob', 'a/b', ''),
    ...     ('glob', 'c/*.d', ''),
    ...     ('glob', 'e/**/*.c', ''),
    ...     ('re', '^f/(?!g)', ''), # no "$", only match prefix
    ...     ('re', '^h/(i|j)$', ''),
    ...     ('glob', 'i/a*/b*/c*', ''),
    ...     ('glob', 'i/a5/b7/d', ''),
    ...     ('glob', 'j/**.c', ''),
    ... ])
    >>> t('a')
    True
    >>> t('a/b')
    'all'
    >>> t('a/b/c')
    'all'
    >>> t('c')
    True
    >>> t('c/d')
    False
    >>> t('c/rc.d')
    'all'
    >>> t('c/rc.d/foo')
    'all'
    >>> t('e')
    True
    >>> t('e/a')
    True
    >>> t('e/a/b.c')
    True
    >>> t('e/a/b.d')
    True
    >>> t('f')
    True
    >>> t('f/g')
    False
    >>> t('f/g2')
    False
    >>> t('f/g/a')
    False
    >>> t('f/h')
    'all'
    >>> t('f/h/i')
    'all'
    >>> t('h/i')
    True
    >>> t('h/i/k')
    False
    >>> t('h/k')
    False
    >>> t('i')
    True
    >>> t('i/a1')
    True
    >>> t('i/b2')
    False
    >>> t('i/a/b2/c3')
    'all'
    >>> t('i/a/b2/d4')
    False
    >>> t('i/a5/b7/d')
    'all'
    >>> t('j/x/y')
    True
    >>> t('z')
    False
    """
    tree = _tree()
    for kind, pat, _source in kindpats:
        if kind == "glob":
            components = []
            for p in pat.split("/"):
                if "[" in p or "{" in p or "*" in p or "?" in p:
                    break
                components.append(p)
            prefix = "/".join(components)
            matchrecursive = prefix == pat
            tree.insert(
                prefix,
                matchrecursive=matchrecursive,
                globpats=_remainingpats(pat, prefix),
            )
        elif kind == "re":
            # Still try to get a plain prefix from the regular expression so we
            # can still have fast paths.
            if pat.startswith("^"):
                # "re" already matches from the beginning, unlike "relre"
                pat = pat[1:]
            components = []
            for p in pat.split("/"):
                if re.escape(p) != p:
                    # contains special characters
                    break
                components.append(p)
            prefix = "/".join(components)
            tree.insert(
                prefix, matchrecursive=False, repats=_remainingpats(pat, prefix)
            )
        else:
            # Unsupported kind
            return None
    return tree.visitdir