Path: blob/master/venv/Lib/site-packages/pip/_internal/vcs/bazaar.py
811 views
# The following comment should be removed at some point in the future.1# mypy: disallow-untyped-defs=False23from __future__ import absolute_import45import logging6import os78from pip._vendor.six.moves.urllib import parse as urllib_parse910from pip._internal.utils.misc import display_path, rmtree11from pip._internal.utils.subprocess import make_command12from pip._internal.utils.typing import MYPY_CHECK_RUNNING13from pip._internal.utils.urls import path_to_url14from pip._internal.vcs.versioncontrol import VersionControl, vcs1516if MYPY_CHECK_RUNNING:17from typing import Optional, Tuple18from pip._internal.utils.misc import HiddenText19from pip._internal.vcs.versioncontrol import AuthInfo, RevOptions202122logger = logging.getLogger(__name__)232425class Bazaar(VersionControl):26name = 'bzr'27dirname = '.bzr'28repo_name = 'branch'29schemes = (30'bzr', 'bzr+http', 'bzr+https', 'bzr+ssh', 'bzr+sftp', 'bzr+ftp',31'bzr+lp',32)3334def __init__(self, *args, **kwargs):35super(Bazaar, self).__init__(*args, **kwargs)36# This is only needed for python <2.7.537# Register lp but do not expose as a scheme to support bzr+lp.38if getattr(urllib_parse, 'uses_fragment', None):39urllib_parse.uses_fragment.extend(['lp'])4041@staticmethod42def get_base_rev_args(rev):43return ['-r', rev]4445def export(self, location, url):46# type: (str, HiddenText) -> None47"""48Export the Bazaar repository at the url to the destination location49"""50# Remove the location to make sure Bazaar can export it correctly51if os.path.exists(location):52rmtree(location)5354url, rev_options = self.get_url_rev_options(url)55self.run_command(56make_command('export', location, url, rev_options.to_args()),57show_stdout=False,58)5960def fetch_new(self, dest, url, rev_options):61# type: (str, HiddenText, RevOptions) -> None62rev_display = rev_options.to_display()63logger.info(64'Checking out %s%s to %s',65url,66rev_display,67display_path(dest),68)69cmd_args = (70make_command('branch', '-q', rev_options.to_args(), url, dest)71)72self.run_command(cmd_args)7374def switch(self, dest, url, rev_options):75# type: (str, HiddenText, RevOptions) -> None76self.run_command(make_command('switch', url), cwd=dest)7778def update(self, dest, url, rev_options):79# type: (str, HiddenText, RevOptions) -> None80cmd_args = make_command('pull', '-q', rev_options.to_args())81self.run_command(cmd_args, cwd=dest)8283@classmethod84def get_url_rev_and_auth(cls, url):85# type: (str) -> Tuple[str, Optional[str], AuthInfo]86# hotfix the URL scheme after removing bzr+ from bzr+ssh:// readd it87url, rev, user_pass = super(Bazaar, cls).get_url_rev_and_auth(url)88if url.startswith('ssh://'):89url = 'bzr+' + url90return url, rev, user_pass9192@classmethod93def get_remote_url(cls, location):94urls = cls.run_command(['info'], show_stdout=False, cwd=location)95for line in urls.splitlines():96line = line.strip()97for x in ('checkout of branch: ',98'parent branch: '):99if line.startswith(x):100repo = line.split(x)[1]101if cls._is_local_repository(repo):102return path_to_url(repo)103return repo104return None105106@classmethod107def get_revision(cls, location):108revision = cls.run_command(109['revno'], show_stdout=False, cwd=location,110)111return revision.splitlines()[-1]112113@classmethod114def is_commit_id_equal(cls, dest, name):115"""Always assume the versions don't match"""116return False117118119vcs.register(Bazaar)120121122