def discover_url(self): location = os.path.normcase(os.path.abspath(os.curdir)) # Pip registers the VCS handlers on import now- kinda lame really. import pip.vcs.subversion import pip.vcs.mercurial import pip.vcs.git backend = vcs.get_backend_from_location(location) self.revision = None if backend: bck = backend() url = bck.get_url(location) self.full_url = url revision = bck.get_revision(location) # This is similar to pip.vcs.subversion.get_src_requirement parts = url.split('/') for i in range(len(parts) - 1, 0, -1): if parts[i] in ('trunk', 'tags', 'tag', 'branch', 'branches'): url = '/'.join(parts[:i]) print "discovered URL for %s backend: %s" % (backend.name, url) self.distribution.metadata.url = url self.revision = revision break else: pass #print "WARNING: This is not a regular repository (no trunk, tags, or branches)" #print " Using discovered URL: %s" % self.distribution.metadata.url else: pass
def discover_url(self): # Pip registers the VCS handlers on import now- kinda lame really. import pip.vcs.subversion # @UnusedImport # NOQA import pip.vcs.mercurial # @UnusedImport # NOQA import pip.vcs.git # @UnusedImport # NOQA location = os.path.normcase(os.path.abspath(os.curdir)) backend = vcs.get_backend_from_location(location) self.revision = None if backend: bck = backend() url = bck.get_url(location) self.full_url = url revision = bck.get_revision(location) # This is similar to pip.vcs.subversion.get_src_requirement parts = url.split('/') for i in range(len(parts) - 1, 0, -1): if parts[i] in ('trunk', 'tags', 'tag', 'branch', 'branches'): url = '/'.join(parts[:i]) print("discovered URL for %s backend: %s" % (backend.name, url)) self.distribution.metadata.url = url self.revision = revision break else: pass else: pass
def get_version_from_location(location, logger): backend_cls = vcs.get_backend_from_location(location) if backend_cls: backend = backend_cls() url, rev = backend.get_info(location) # Mercurial sometimes returns something like # "Not trusting file /home/alice/repo/.hg/hgrc from untrusted user alice, group users" # We'll ignore it for now if len(url) > 250 or len(rev) > 100: return None url = annotate_url_with_ssh_config_info(url, logger) if backend_cls.name not in VCS_NAME_MAP: return None vcs_type = VCS_NAME_MAP[backend_cls.name] return {'type': vcs_type, 'revision': rev, 'repository': url} else: head, tail = os.path.split(location) if head and head != '/': # TODO: Support windows return get_version_from_location(head, logger) else: return None
def from_path(cls, path): backend_class = vcs.get_backend_from_location(path) if backend_class: backend = backend_class() try: remote_url = backend.get_url(path) except InstallationError: remote_url = None return VCS( vcs_type=VCS_NAME_MAP[backend.name], rev=backend.get_revision(path), remote_url=remote_url, branch=get_branch(backend, path), )