1
from __future__ import absolute_import
7
# TODO: Get this into six.moves.urllib.parse
9
from urllib import parse as urllib_parse
11
import urlparse as urllib_parse
13
from pip.utils import rmtree, display_path
14
from pip.vcs import vcs, VersionControl
15
from pip.download import path_to_url
18
logger = logging.getLogger(__name__)
21
class Bazaar(VersionControl):
26
'bzr', 'bzr+http', 'bzr+https', 'bzr+ssh', 'bzr+sftp', 'bzr+ftp',
30
def __init__(self, url=None, *args, **kwargs):
31
super(Bazaar, self).__init__(url, *args, **kwargs)
32
# Python >= 2.7.4, 3.3 doesn't have uses_fragment or non_hierarchical
33
# Register lp but do not expose as a scheme to support bzr+lp.
34
if getattr(urllib_parse, 'uses_fragment', None):
35
urllib_parse.uses_fragment.extend(['lp'])
36
urllib_parse.non_hierarchical.extend(['lp'])
38
def export(self, location):
40
Export the Bazaar repository at the url to the destination location
42
temp_dir = tempfile.mkdtemp('-export', 'pip-')
44
if os.path.exists(location):
45
# Remove the location to make sure Bazaar can export it correctly
48
self.run_command(['export', location], cwd=temp_dir,
53
def switch(self, dest, url, rev_options):
54
self.run_command(['switch', url], cwd=dest)
56
def update(self, dest, rev_options):
57
self.run_command(['pull', '-q'] + rev_options, cwd=dest)
59
def obtain(self, dest):
60
url, rev = self.get_url_rev()
62
rev_options = ['-r', rev]
63
rev_display = ' (to revision %s)' % rev
67
if self.check_destination(dest, url, rev_options, rev_display):
69
'Checking out %s%s to %s',
74
self.run_command(['branch', '-q'] + rev_options + [url, dest])
76
def get_url_rev(self):
77
# hotfix the URL scheme after removing bzr+ from bzr+ssh:// readd it
78
url, rev = super(Bazaar, self).get_url_rev()
79
if url.startswith('ssh://'):
83
def get_url(self, location):
84
urls = self.run_command(['info'], show_stdout=False, cwd=location)
85
for line in urls.splitlines():
87
for x in ('checkout of branch: ',
89
if line.startswith(x):
90
repo = line.split(x)[1]
91
if self._is_local_repository(repo):
92
return path_to_url(repo)
96
def get_revision(self, location):
97
revision = self.run_command(
98
['revno'], show_stdout=False, cwd=location)
99
return revision.splitlines()[-1]
101
def get_src_requirement(self, dist, location):
102
repo = self.get_url(location)
105
if not repo.lower().startswith('bzr:'):
107
egg_project_name = dist.egg_name().split('-', 1)[0]
108
current_rev = self.get_revision(location)
109
return '%s@%s#egg=%s' % (repo, current_rev, egg_project_name)
111
def check_version(self, dest, rev_options):
112
"""Always assume the versions don't match"""