def expand_ssh_host_alias(url, config=None): """Return ``url`` with the real host name if it has an SSH alias.""" config = config or _get_ssh_config() if config: DUMMY_SCHEME = "opbeat-dummy://" parts = urlsplit(url) if not parts.scheme: # If scheme is not present in the URL, the whole URL # gets interpretted as path, and we don't like that. parts = urlsplit(DUMMY_SCHEME + url) host_alias = parts.netloc.split("@")[-1].split(":")[0] host_expanded = config.lookup(host_alias).get("hostname") if host_expanded: netloc = parts.netloc.replace(host_alias, host_expanded, 1) parts = list(parts) # [scheme, netloc, path, query, fragment] parts[1] = netloc url = urlunsplit(parts) if url.startswith(DUMMY_SCHEME): url = url[len(DUMMY_SCHEME) :] return url
def parse_editable(uri): """ <remote_url>@<rev>#egg=<name> See `pip.vcs.<backend>.<Backend>.get_src_requirement()`. """ bits = urlsplit(uri) remove_scheme = False if not bits.scheme: # [email protected]:opbeat/opbeatcli.git@a2794#egg=opbeatcli-dev assert uri.startswith('git+') uri = 'git://' + uri[4:] bits = urlsplit(uri) remove_scheme = True remote_url = uri.rsplit('@', 1)[0] if '+' in bits.scheme: vcs_type, remote_url = remote_url.split('+', 1) else: assert bits.scheme == 'git', bits.scheme vcs_type = 'git' if '#' in bits.path: # Python 2.6 sometimes fails to parse fragment. # /ipython/ipython.git@rev#egg=ipython-dev rev, name = bits.path.split('@')[1].split('#egg=') else: name = bits.fragment.split('=', 1)[1] rev = bits.path.split('@')[1] if remove_scheme: remote_url = remote_url[len(bits.scheme) + 3:] version = None if vcs_type in ['git', 'hg', 'bzr']: # There is no version as such, but each of the VCS backends appends # some VCS info to the name (or just '-dev'). SVN is tricky, so we # don't parse the name there. name, version = name.rsplit('-', 1) parsed = { 'name': name, 'version': version, 'vcs': { 'vcs_type': VCS_NAME_MAP[vcs_type], 'rev': rev, 'remote_url': remote_url, } } assert all([parsed['name'], parsed['vcs']['rev'], parsed['vcs']['vcs_type'], parsed['vcs']['remote_url']]), parsed return parsed